diff options
author | Florian Weimer <fweimer@redhat.com> | 2021-07-15 08:28:50 +0200 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2021-07-15 09:00:27 +0200 |
commit | 820bb23ff074db8255217ab01b51f28c96ec76a9 (patch) | |
tree | 14bb3922ac81a76d8f2124215682644a4a05e96c /resolv/ns_name.c | |
parent | ee3639e0fe61a3692adf660e04f9e6d56475ff52 (diff) | |
download | glibc-820bb23ff074db8255217ab01b51f28c96ec76a9.zip glibc-820bb23ff074db8255217ab01b51f28c96ec76a9.tar.gz glibc-820bb23ff074db8255217ab01b51f28c96ec76a9.tar.bz2 |
resolv: Move ns_name_unpack to its own file and into libc
Reformat to GNU style. Avoid out-of-bounds buffer arithmetic.
Eliminate the labellen function.
The symbol was moved using scripts/move-symbol-to-libc.py.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'resolv/ns_name.c')
-rw-r--r-- | resolv/ns_name.c | 81 |
1 files changed, 0 insertions, 81 deletions
diff --git a/resolv/ns_name.c b/resolv/ns_name.c index 4990003..a0d541f 100644 --- a/resolv/ns_name.c +++ b/resolv/ns_name.c @@ -218,87 +218,6 @@ ns_name_ntol(const u_char *src, u_char *dst, size_t dstsiz) } /*% - * Unpack a domain name from a message, source may be compressed. - * - * return: - *\li -1 if it fails, or consumed octets if it succeeds. - */ -int -ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src, - u_char *dst, size_t dstsiz) -{ - const u_char *srcp, *dstlim; - u_char *dstp; - int n, len, checked, l; - - len = -1; - checked = 0; - dstp = dst; - srcp = src; - dstlim = dst + dstsiz; - if (srcp < msg || srcp >= eom) { - __set_errno (EMSGSIZE); - return (-1); - } - /* Fetch next label in domain name. */ - while ((n = *srcp++) != 0) { - /* Check for indirection. */ - switch (n & NS_CMPRSFLGS) { - case 0: - /* Limit checks. */ - if ((l = labellen(srcp - 1)) < 0) { - __set_errno (EMSGSIZE); - return(-1); - } - if (dstp + l + 1 >= dstlim || srcp + l >= eom) { - __set_errno (EMSGSIZE); - return (-1); - } - checked += l + 1; - *dstp++ = n; - memcpy(dstp, srcp, l); - dstp += l; - srcp += l; - break; - - case NS_CMPRSFLGS: - if (srcp >= eom) { - __set_errno (EMSGSIZE); - return (-1); - } - if (len < 0) - len = srcp - src + 1; - srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff)); - if (srcp < msg || srcp >= eom) { /*%< Out of range. */ - __set_errno (EMSGSIZE); - return (-1); - } - checked += 2; - /* - * Check for loops in the compressed name; - * if we've looked at the whole message, - * there must be a loop. - */ - if (checked >= eom - msg) { - __set_errno (EMSGSIZE); - return (-1); - } - break; - - default: - __set_errno (EMSGSIZE); - return (-1); /*%< flag error */ - } - } - *dstp = '\0'; - if (len < 0) - len = srcp - src; - return (len); -} -libresolv_hidden_def (ns_name_unpack) -strong_alias (ns_name_unpack, __ns_name_unpack) - -/*% * Pack domain name 'domain' into 'comp_dn'. * * return: |