1 /* De-compressing DNS domain names into binary-encoded uncompressed name.
2 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (c) 1996,1999 by Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
15 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <arpa/nameser.h>
20 #include <shlib-compat.h>
24 /* Unpack a domain name from a message, source may be compressed.
25 Returns -1 if it fails, or consumed octets if it succeeds. */
27 ___ns_name_unpack (const unsigned char *msg
, const unsigned char *eom
,
28 const unsigned char *src
, unsigned char *dst
, size_t dstsiz
)
30 const unsigned char *srcp
, *dstlim
;
38 dstlim
= dst
+ dstsiz
;
39 if (srcp
< msg
|| srcp
>= eom
)
41 __set_errno (EMSGSIZE
);
44 /* Fetch next label in domain name. */
45 while ((n
= *srcp
++) != 0)
47 /* Check for indirection. */
48 switch (n
& NS_CMPRSFLGS
)
54 __set_errno (EMSGSIZE
);
57 /* NB: n + 1 and >= to cover the *dstp = '\0' assignment
59 if (n
+ 1 >= dstlim
- dstp
|| n
>= eom
- srcp
)
61 __set_errno (EMSGSIZE
);
66 memcpy (dstp
, srcp
, n
);
74 __set_errno (EMSGSIZE
);
80 int target
= ((n
& 0x3f) << 8) | *srcp
;
81 if (target
>= eom
- msg
)
84 __set_errno (EMSGSIZE
);
90 /* Check for loops in the compressed name; if we've looked
91 at the whole message, there must be a loop. */
92 if (checked
>= eom
- msg
)
94 __set_errno (EMSGSIZE
);
100 __set_errno (EMSGSIZE
);
109 versioned_symbol (libc
, ___ns_name_unpack
, ns_name_unpack
, GLIBC_2_34
);
110 versioned_symbol (libc
, ___ns_name_unpack
, __ns_name_unpack
, GLIBC_PRIVATE
);
111 libc_hidden_ver (___ns_name_unpack
, __ns_name_unpack
)
113 #if OTHER_SHLIB_COMPAT (libresolv, GLIBC_2_9, GLIBC_2_34)
114 compat_symbol (libresolv
, ___ns_name_unpack
, ns_name_unpack
, GLIBC_2_9
);