-
Notifications
You must be signed in to change notification settings - Fork 844
TS-4313: Fix improper type conversion #542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Nice catch! +1. I think we should mark this as a possibly back port to 6.1.2 as well. Do you know if this bug is in 5.3.x as well? If so, it likely should go there as well. |
proxy/hdrs/MIME.cc
Outdated
| { | ||
| int slot_id, slot_num; | ||
| int slot_id; | ||
| intptr_t slot_num; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to be needed?
|
That said, I don't really understand the problem here. If A potential real problem here could be the compiler assuming that the comparison can't happen, since pointer arithmetic across different objects is not standards compliant, see here. To address this, I'd add int
mime_hdr_field_slotnum(MIMEHdrImpl *mh, MIMEField *field)
{
int slots_so_far;
MIMEFieldBlockImpl *fblock;
slots_so_far = 0;
for (fblock = &(mh->m_first_fblock); fblock != NULL; fblock = fblock->m_next) {
if (block->contains(field)) {
MIMEField *first = &(fblock->m_field_slots[0]);
ptrdiff_t block_slot = field - first; // in units of MIMEField
return (slots_so_far + block_slot);
}
slots_so_far += MIME_FIELD_BLOCK_SLOTS;
}
return -1;
}Can you think of a way to write tests for this? |
|
@jpeach Output: Debug code1: if ((int)(field - &(mh->m_first_fblock.m_field_slots[0])) >= 0 && (int)(field - &(mh->m_first_fblock.m_field_slots[0])) < MIME_FIELD_SLOTNUM_UNKNOWN && slot_num > UINT_MAX) {
fprintf(stderr, "mime_hdr_set_accelerators_and_presence_bits(hdr %p, field %p): &(mh->m_first_fblock.m_field_slots[0]) = %p\n", mh, field, &(mh->m_first_fblock.m_field_slots[0]));
fprintf(stderr, "(int)(field - &(mh->m_first_fblock.m_field_slots[0])) = 0x%X\n", (int)(field - &(mh->m_first_fblock.m_field_slots[0])));
fprintf(stderr, "(long)(field - &(mh->m_first_fblock.m_field_slots[0])) = 0x%lX\n", (long)(field - &(mh->m_first_fblock.m_field_slots[0])));
fprintf(stderr, "(ptrdiff_t)(field - &(mh->m_first_fblock.m_field_slots[0])) = 0x%tX\n", (ptrdiff_t)(field - &(mh->m_first_fblock.m_field_slots[0])));
}Debug code2: if ((int)(field - first) >= 0 && (int)(field - first) < MIME_FIELD_BLOCK_SLOTS && block_slot > UINT_MAX) {
fprintf(stderr, "mime_hdr_field_slotnum(hdr %p, field %p): first = %p\n", mh, field, first);
fprintf(stderr, "(int)(field - first) = 0x%X\n", (int)(field - first));
fprintf(stderr, "(long)(field - first) = 0x%lX\n", (long)(field - first));
fprintf(stderr, "(ptrdiff_t)(field - first) = 0x%tX\n", (ptrdiff_t)(field - first));
}However the problem doesn't seems to be caused by the optimization, adding As for the tests, I had no idea. I came across the bug while I was testing HPACK, which just uses a MIMEHdr heavily. It may be possible to write tests for
@zwoop |
|
Oh interesting. It looks like the pointers are ~500GB apart, so that certainly confirms the problem you found! I wonder if that is specific to the ASAN virtual address space? Anyway, it sounds like we agree on adding |
a2c804a to
ce2bd9e
Compare
|
I've added contains() and tests for this. |
proxy/hdrs/MIME.cc
Outdated
| } | ||
|
|
||
| bool | ||
| MIMEFieldBlockImpl::contains(MIMEField *field) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const MIMEField *field
a4cfc22 to
4a692b6
Compare
The old logic picks up a wrong block due to overflow that is caused by improper type conversion. This fixes the type conversion and make sure that the block contains the field.
* Add OTHER to cipher TLS cipher metrics * clang-format
* Revert "Gauge to Counter metrics for CDN Harmony (apache#544)" This reverts commit 1a83589. * Revert "[9.2.x] Improve performance of finding SNI Actions (apache#541)" This reverts commit 21cbfc0. * Revert "TSan: Make Thread::cur_time thread local (apache#9184) (apache#537)" This reverts commit d93ac0e. * Revert "Fix a crash in FetchSM (apache#546)" This reverts commit e03b829. * Revert "Remove dependency on OpenSSL's OCSP API (apache#538)" This reverts commit 00ad803. * Revert "Fix crashes on OCSP requests (apache#543)" This reverts commit bbb41b9. * Revert "Add OTHER to cipher TLS cipher metrics (apache#542)" This reverts commit 74dbd97. * Revert "rio: use bazinga-boringssl 19.x for boringssl build (apache#540)" This reverts commit 9c57330. * Revert "Use FetchSM for OCSP HTTP requests (apache#535)" This reverts commit dbd0ec7. * Do not schedule reconfigure event on schedule_imm_local Co-authored-by: Mo Chen <mochen@apache.org> Co-authored-by: Serris Lew <lserris@apple.com>
https://issues.apache.org/jira/browse/TS-4313