diff --git a/lib/libc/nameser/ns_name.c b/lib/libc/nameser/ns_name.c index 0c1f93c06629..cbd8f6a886ca 100644 --- a/lib/libc/nameser/ns_name.c +++ b/lib/libc/nameser/ns_name.c @@ -461,11 +461,12 @@ ns_name_unpack2(const u_char *msg, const u_char *eom, const u_char *src, } if (len < 0) len = srcp - src + 1; - srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff)); - if (srcp < msg || srcp >= eom) { /*%< Out of range. */ + l = ((n & 0x3f) << 8) | (*srcp & 0xff); + if (l >= eom - msg) { /*%< Out of range. */ errno = EMSGSIZE; return (-1); } + srcp = msg + l; checked += 2; /* * Check for loops in the compressed name;