-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Description
In https://github.com/jbangert/nail/blob/master/examples/dns/dns.c there is this snippet:
pos = highbyte & 63 << 8 | current->data[pos];
or
pos = highbyte & 63 << 8 | etc;
In C, the operator precedence is <<, then &, then |, so that the equivalent parenthesized expression is:
pos = (highbyte & (63 << 8)) | etc;
Folding the 63<<8 constant gives:
pos = (highbyte & 0x3F00) | etc;
highbyte is a uint8_t, obviously in the range [0x00, 0xFF], so and'ing it with 0x3F00 will always be zero:
pos = 0 | etc;
which simplifies to:
pos = etc;
which is:
pos = current->data[pos];
which is clearly an error, as it ignores the highbyte value. Presumably the original statement should have been:
pos = (highbyte & 63) << 8 | current->data[pos];
although it's not obvious if that is still semantically correct, for compressed DNS records.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels