Bug 19413 - ns_name_unpack: UB when checking for out of range addresses
Summary: ns_name_unpack: UB when checking for out of range addresses
Status: NEW
Alias: None
Product: glibc
Classification: Unclassified
Component: network (show other bugs)
Version: 2.22
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-12-28 14:14 UTC by Alexander Cherepanov
Modified: 2016-09-18 13:26 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Cherepanov 2015-12-28 14:14:05 UTC
ns_name_unpack has the following code:

 425                         srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff));
 426                         if (srcp < msg || srcp >= eom) {  /*%< Out of range. */

https://sourceware.org/git/?p=glibc.git;a=blob;f=resolv/ns_name.c;h=f355cf34443c46d091157ed06f4ef8487214bf10;hb=HEAD#l425

This code is invalid C. The sum "msg + ..." is undefined by the C standard when the result doesn't point into the same array. Then, checks for pointer wrapping like "srcp < msg" are already "miscompiled" by clang and, I guess, could be expected to be broken by gcc in the future.

Similar to pr19391.