The public parser functions around the ns_rr record type produce
textual domain names, but usually, this is not what we need while
parsing DNS packets within glibc. This commit adds two new helper
functions, __ns_rr_cursor_init and __ns_rr_cursor_next, for writing
packet parsers, and struct ns_rr_cursor, struct ns_rr_wire as
supporting types.
In theory, it is possible to avoid copying the owner name
into the rname field in __ns_rr_cursor_next, but this would need
more functions that work on compressed names.
Eventually, __res_context_send could be enhanced to preserve the
result of the packet parsing that is necessary for matching the
incoming UDP packets, so that this works does not have to be done
twice.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
This function is useful for checking that the question name is
uncompressed (as it should be).
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
During packet parsing, only the binary name is available. If the name
equality check is performed before conversion to text, we can sometimes
skip the last step.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
But only as an internal symbol, __libc_ns_samename. The libresolv
ABI is preserved. This is because the function is deprecated, and
it does not make sense to add new symbol versions for deprecated
functions.
Also reformat the implementation to GNU style.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
But only as an internal symbol, __libc_ns_makecanon. The libresolv
ABI is preserved. This is because the function is deprecated, and
it does not make sense to add new symbol versions for deprecated
functions.
Also reformat the implementation to GNU style.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
And reformat to GNU style.
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>
And reformat to GNU style, and 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>
And reformat to GNU style, and eliminate the digits variable.
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>
And reformat to GNU style. Check for negative error returns
(instead of -1).
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>
And reformat to GNU style. Avoid out-of-bounds pointer arithmetic.
This also results in a fix of bug 28091 due to the additional packet
length checks.
The symbol was moved using scripts/move-symbol-to-libc.py.
Reviewed-by: Carlos O'Donell <carlos@systemhalted.org>
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>
Reformat to GNU style. Avoid out-of-bounds pointer arithmetic
(e.g., use eom - dn < 2 instead of dn + 1 >= eom). Inline the
labellen function and fold the compression pointer check into
the length check (l >= 64). Assume ASCII encoding.
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>
The IPv4 address parser in the getaddrinfo function is changed so that
it does not ignore trailing whitespace and all characters after it.
For backwards compatibility, the getaddrinfo function still recognizes
legacy name syntax, such as 192.000.002.010 interpreted as 192.0.2.8
(octal).
This commit does not change the behavior of inet_addr and inet_aton.
gethostbyname already had additional sanity checks (but is switched
over to the new __inet_aton_exact function for completeness as well).
To avoid sending the problematic query names over DNS, commit
6ca53a2453 ("resolv: Do not send queries
for non-host-names in nss_dns [BZ #24112]") is needed.
This adds a test to ensure that the problems fixed in the last several
patches do not recur. Each directory checks the headers that it
installs for two properties: first, each header must be compilable in
isolation, as both C and C++, under a representative combination of
language and library conformance levels; second, there is a blacklist
of identifiers that may not appear in any installed header, currently
consisting of the legacy BSD typedefs. (There is an exemption for the
headers that define those typedefs, and for the RPC headers. It may be
necessary to make this more sophisticated if we add more stuff to the
blacklist in the future.)
In order for this test to work correctly, every wrapper header
that actually defines something must guard those definitions with
#ifndef _ISOMAC. This is the existing mechanism used by the conform/
tests to tell wrapper headers not to define anything that the public
header wouldn't, and not to use anything from libc-symbols.h. conform/
only cares for headers that we need to check for standards conformance,
whereas this test applies to *every* header. (Headers in include/ that
are either installed directly, or are internal-use-only and do *not*
correspond to any installed header, are not affected.)
* scripts/check-installed-headers.sh: New script.
* Rules: In each directory that defines header files to be installed,
run check-installed-headers.sh on them as a special test.
* Makefile: Likewise for the headers installed at top level.
* include/aliases.h, include/alloca.h, include/argz.h
* include/arpa/nameser.h, include/arpa/nameser_compat.h
* include/elf.h, include/envz.h, include/err.h
* include/execinfo.h, include/fpu_control.h, include/getopt.h
* include/gshadow.h, include/ifaddrs.h, include/libintl.h
* include/link.h, include/malloc.h, include/mcheck.h
* include/mntent.h, include/netinet/ether.h
* include/nss.h, include/obstack.h, include/printf.h
* include/pty.h, include/resolv.h, include/rpc/auth.h
* include/rpc/auth_des.h, include/rpc/auth_unix.h
* include/rpc/clnt.h, include/rpc/des_crypt.h
* include/rpc/key_prot.h, include/rpc/netdb.h
* include/rpc/pmap_clnt.h, include/rpc/pmap_prot.h
* include/rpc/pmap_rmt.h, include/rpc/rpc.h
* include/rpc/rpc_msg.h, include/rpc/svc.h
* include/rpc/svc_auth.h, include/rpc/xdr.h
* include/rpcsvc/nis_callback.h, include/rpcsvc/nislib.h
* include/rpcsvc/yp.h, include/rpcsvc/ypclnt.h
* include/rpcsvc/ypupd.h, include/shadow.h
* include/stdio_ext.h, include/sys/epoll.h
* include/sys/file.h, include/sys/gmon.h, include/sys/ioctl.h
* include/sys/prctl.h, include/sys/profil.h
* include/sys/statfs.h, include/sys/sysctl.h
* include/sys/sysinfo.h, include/ttyent.h, include/utmp.h
* sysdeps/arm/nacl/include/bits/setjmp.h
* sysdeps/mips/include/sys/asm.h
* sysdeps/unix/sysv/linux/include/sys/sysinfo.h
* sysdeps/unix/sysv/linux/include/sys/timex.h
* sysdeps/x86/fpu/include/bits/fenv.h:
Add #ifndef _ISOMAC guard around internal declarations.
Add multiple-inclusion guard if not already present.
The types u_char, u_short, u_int, u_long, ushort, uint, ulong, u_int8_t,
u_int16_t, u_int32_t, u_int64_t, quad_t, and u_quad_t are BSDisms that
have never been standardized. While glibc should continue to *provide*
these types for compatibility's sake, its public headers should not
use them.
The meat of this change was mechanically generated by the following
shell command:
perl -pi~ -e '
s/\b(__)?u_char\b/unsigned char/g;
s/\b(__)?u_?short\b/unsigned short/g;
s/\b(__)?u_?int\b/unsigned int/g;
s/\b(__)?u_?long\b/unsigned long/g;
s/\b(__)?u_int8_t\b/uint8_t/g;
s/\b(__)?u_int16_t\b/uint16_t/g;
s/\b(__)?u_int32_t\b/uint32_t/g;
s/\b(__)?u_int64_t\b/uint64_t/g;
s/\b(__)?u_quad_t\b/uint64_t/g;
s/\b(__)?quad_t\b/uint64_t/g;
' $(grep -lE -e '\<((__)?(quad_t|u(short|int|long|_(char|short|int([0-9]+_t)?|long|quad_t))))\>' \
$(grep -LE '\<(_(SYS|BITS)_TYPES_H|rpc/(rpc|rpc_msg|types|xdr)\.h)\>' \
$(find . \( -false $(sed 's/^/-o -name /' all-installed-headers) \
\) -printf '%P\n' | sort -u)))
where 'all-installed-headers' was a list of the basenames of all installed
header files, manually extracted from the Makefiles. Non-installed
wrapper headers in include/ are also adjusted, for consistency.
I then manually fixed up indentation and line-wrapping.
sys/types.h and bits/types.h are excluded because they must continue
to define the u_* types (under __USE_MISC) for compatibility with
applications. They do not use these types themselves.
All headers that (transitively) include rpc/types.h are also excluded,
for three reasons. First, the u_* types are defined by rpc/types.h,
unconditionally (not just under __USE_MISC) so they are logically part
of the SunRPC API. Second, many of those headers appear to be
machine-generated. Third, it's my understanding that we are getting
rid of as much of SunRPC as possible in the near future.
(The one file under sunrpc/ that's touched, sunrpc/rpc/rpc_des.h, does
*not* include rpc/types.h. This may itself be a bug.)
After changing from u_intNN_t to uintNN_t, a number of headers now
need to include stdint.h to pick up those types. It might be more
hygenic, namespace-wise, to use __uintNN_t instead, but none of these
headers are bound by ISO or POSIX to do so, and it's unlikely that
anyone using them will be bothered. (The two files that were using
__-prefixed versions of the u_types, sysdeps/mach/hurd/net/route.h and
sysdeps/unix/sysv/linux/net/route.h, both already also contained uses of
the unprefixed versions.)
Some of these files directly included features.h and/or sys/cdefs.h,
which I removed, as the style generally seems to be to let sys/types.h
do that for us. (This does not change the set of definitions exposed
by any header; sys/types.h unconditionally includes both features.h
and sys/cdefs.h.)
One file included asm/types.h unnecessarily.
* bits/in.h, gmon/sys/gmon.h, inet/netinet/igmp.h
* inet/protocols/routed.h, inet/protocols/talkd.h
* inet/protocols/timed.h, io/fts.h, nptl_db/thread_db.h
* resolv/arpa/nameser.h, resolv/resolv.h, sunrpc/rpc/rpc_des.h
* sysdeps/generic/netinet/if_ether.h
* sysdeps/generic/netinet/in_systm.h
* sysdeps/generic/netinet/ip.h, sysdeps/generic/netinet/tcp.h
* sysdeps/gnu/netinet/ip_icmp.h, sysdeps/gnu/netinet/tcp.h
* sysdeps/gnu/netinet/udp.h, sysdeps/mach/hurd/net/ethernet.h
* sysdeps/mach/hurd/net/if_arp.h
* sysdeps/mach/hurd/net/if_ppp.h
* sysdeps/mach/hurd/net/route.h, sysdeps/mach/sys/reboot.h
* sysdeps/unix/sysv/linux/bits/in.h
* sysdeps/unix/sysv/linux/net/ethernet.h
* sysdeps/unix/sysv/linux/net/if_arp.h
* sysdeps/unix/sysv/linux/net/if_ppp.h
* sysdeps/unix/sysv/linux/net/if_shaper.h
* sysdeps/unix/sysv/linux/net/route.h
* sysdeps/unix/sysv/linux/netinet/if_ether.h
* sysdeps/unix/sysv/linux/netinet/if_fddi.h
* sysdeps/unix/sysv/linux/netinet/if_tr.h
* sysdeps/unix/sysv/linux/netipx/ipx.h
* sysdeps/unix/sysv/linux/sys/acct.h
* include/arpa/nameser.h, include/resolv.h:
Change all uses of u_char to unsigned char,
u_short and ushort to unsigned short, u_int and uint to unsigned int,
u_long and ulong to unsigned long, u_int8_t to uint8_t,
u_int16_t to uint16_t, u_int32_t to uint32_t, quad_t to int64_t,
and u_int64_t and u_quad_t to uint64_t.
* mach/sys/reboot.h: Remove two casts of integer literals
to the types they already have.
* bits/in.h: Correct error in description of IP_MULTICAST_LOOP.
* sysdeps/unix/sysv/linux/bits/in.h: Likewise.
* sysdeps/unix/sysv/linux/netinet/if_ether.h: Change a comment
from referring to 'unsigned char' to 'uint8_t' for consistency with
the macro definition below.
* gmon/sys/gmon.h, inet/netinet/igmp.h, inet/protocols/talkd.h
* io/fts.h, resolv/arpa/nameser.h, resolv/resolv.h
* sunrpc/rpc/rpc_des.h, sysdeps/generic/netinet/ip.h
* sysdeps/gnu/netinet/tcp.h, sysdeps/gnu/netinet/udp.h
* sysdeps/mach/hurd/net/if_ppp.h, sysdeps/unix/sysv/linux/net/if_ppp.h
* sysdeps/unix/sysv/linux/sys/acct.h
* include/arpa/nameser.h, include/resolv.h:
Fix indentation disrupted by mechanical edits.
* inet/protocols/talkd.h, resolv/arpa/nameser.h
* sysdeps/generic/netinet/in_systm.h
* sysdeps/gnu/netinet/ip_icmp.h, sysdeps/gnu/netinet/tcp.h
* sysdeps/gnu/netinet/udp.h
* sysdeps/unix/sysv/linux/net/ethernet.h
* sysdeps/unix/sysv/linux/net/if_arp.h
* sysdeps/unix/sysv/linux/net/if_ppp.h
* sysdeps/unix/sysv/linux/net/if_shaper.h
* sysdeps/unix/sysv/linux/netinet/if_fddi.h
* sysdeps/unix/sysv/linux/netinet/if_tr.h
* sysdeps/unix/sysv/linux/netipx/ipx.h
* sysdeps/unix/sysv/linux/sys/acct.h
Include stdint.h for uintNN_t definitions.
Don't include sys/cdefs.h, features.h, or asm/types.h directly.
Parts of the resolver brought in by pthreads (at least) use inet_*
functions that aren't in the 1995/6 edition of POSIX that introduced
pthreads (or in one case, use __inet_aton which is then defined in the
same file as non-weak inet_addr). This patch fixes this by making the
affected functions into weak alias for __inet_* and using those names
in the problematic resolver code.
Tested for x86_64 (testsuite, and that disassembly of installed shared
libraries is unchanged by the patch).
[BZ #17722]
* inet/inet_mkadr.c (inet_makeaddr): Rename to __inet_makeaddr and
define as weak alias of __inet_makeaddr.
* resolv/inet_addr.c (inet_addr): Rename to __inet_addr and define
as weak alias of __inet_addr.
* resolv/inet_pton.c (inet_pton): Rename to __inet_pton and define
as weak alias of __inet_pton. Use libc_hidden_weak.
* include/arpa/inet.h (__inet_pton): Declare. Use
libc_hidden_proto.
(inet_makeaddr): Don't use libc_hidden_proto.
(__inet_makeaddr): Declare. Use libc_hidden_proto.
* resolv/res_init.c (__res_vinit): Use __inet_pton instead of
inet_pton. Use __inet_makeaddr instead of inet_makeaddr.
* conform/Makefile (test-xfail-POSIX/pthread.h/linknamespace):
Remove variable.
(test-xfail-POSIX/sched.h/linknamespace): Likewise.
(test-xfail-POSIX/time.h/linknamespace): Likewise.
* include/resolv.h: Remove hidden proto declarations for __ns_*
functions. Add them for __dn_count_labels and __p_secstodate.
* include/arpa/nameser.h: Add a number of hidden proto declarations.
Define ns_msg_getflags macro here.
* resolv/res_debug.c: Add hidden definition for __dn_count_labels
and __p_secstodate.
* resolv/Versions: Export functions from <arpa/nameser.h> from
libresolv in version GLIBC_2.9.
* resolv/ns_name.c: Integrate changes from bind 9.5.0. Add necessary
hidden definitions.
* resolv/ns_netint.c: Likewise.
* resolv/ns_parse.c: Likewise.
* resolv/ns_print.c: Likewise.
* resolv/ns_samedomain.c: Likewise.
* resolv/ns_ttl.c: Likewise.
* resolv/arpa/nameser_compat.h: Likewise.
* resolv/arpa/nameser.h: Likewise. Remove macros which redirect
function calls.
* resolv/nss_dns/dns-canon.c (_nss_dns_getcanonname_r): Use __ns_get16
instead of ns_get16.
* resolv/nss_dns/dns-host.c (getanswer_r): Use __ns_get16 and
__ns_get32 instead of ns_get16 and ns_get32 respectively.
(gaih_getanswer_slice): Likewise.
* resolv/Makefile (libresolv-routines): Add ns_date.
* resolv/ns_date.c: New file.
prototypes.
* include/arpa/nameser_compat.h: Define T_UNSPEC.
* nis/Versions (libnss_nis): Export _nss_nis_gethostbyname4_r.
(libnss_nisplus): Export _nss_nisplus_gethostbyname4_r.
* nis/nss_nis/nis-hosts.c (LINE_PARSER): Change to also handle
af==AF_UNSPEC.
(_nss_nis_gethostbyname4_r): New function.
* nis/nss_nisplus/nisplus-hosts.c (_nss_nisplus_parse_hostent):
Change to also handle af==AF_UNSPEC.
(get_tablename): New function. Use it to avoid duplication.
(_nss_nisplus_gethostbyname4_r): New function.
* nscd/aicache.c (addhstaiX): Use gethostbyname4_r function is
available.
* nss/Versions (libnss_files): Export _nss_files_gethostbyname4_r.
* nss/nss.h: Define struct gaih_addrtuple.
* nss/nss_files/files-hosts.c (LINE_PARSER): Change to also handle
af==AF_UNSPEC.
(_nss_files_gethostbyname4_r): New function.
* resolv/Versions (libnss_dns): Export _nss_dns_gethostbyname4_r.
* resolv/gethnmaddr.c: Adjust __libc_res_nsearch and __libc_res_nquery
calls.
* resolv/res_query.c (__libc_res_nquery): Take two additional
parameters for second answer buffer. Handle type=T_UNSPEC to mean
look up IPv4 and IPv6.
Change all callers.
* resolv/res_send.c (__libc_res_nsend): Take five aditional parameters
for an additional query and answer buffer. Pass to send_vc and
send_dg.
(send_vc): Send possibly two requests and receive two answers.
(send_dg): Likewise.
* resolv/nss_dns/dns-host.c: Adjust calls to __libc_res_nsearch and
__libc_res_nquery.
(_nss_dns_gethostbyname4_r): New function.
(gaih_getanswer_slice): Likewise.
(gaih_getanswer): Likewise.
* resolv/nss_dns/dns-canon.c (_nss_dns_getcanonname_r): Adjust
__libc_res_nquery call.
* resolv/nss_dns/dns-network.c (_nss_dns_getnetbyaddr_r): Likewise.
(_nss_dns_getnetbyname_r): Adjust __libc_res_nsearch call.
* sysdeps/posix/getaddrinfo.c: Use gethostbyname4_r function is
available.
* resolv/res_mkquery.c: Use NS_PUT16 and NS_PUT32 instead of __putshort
and __putlong respectively. Correct buffer overflow check for
NS_NOTIFY_OP.
* resolv/res_send.c (send_vc): Use ns_put16 instead of putshort.
1999-12-03 Andreas Jaeger <aj@suse.de>
* nss/getXXbyYY.c: Include <resolv.h>
(FUNCTION_NAME): Use res_ninit instead of res_init.
* nss/getXXbyYY_r.c [NEED__RES]: Include <resolv.h> for _res
declaration and prototypes.
Remove extra _res declaration.
(INTERNAL): Use thread aware res_ninit function.
* inet/gethstbyad_r.c: Include <resolv.h>.
* resolv/res_data.c: Update from Bind 8.2.2-P5. Moved res_init to
res_libc.c. Disabled unneeded functions.
* resolv/res_libc.c: New file.
* Versions.def: Add version GLIBC_2.2 for libpthread.
Add versions GLIBC_2.1 and GLIBC_2.2 for libresolv.
* include/resolv.h: Add internal interfaces.
* resolv/Makefile (routines): Add new files.
(libresolv-routines): Likewise.
(distribute): Likewise.
* resolv/gethnamaddr.c: Use thread safe resolver functions.
* resolv/nss_dns/dns-host.c: Likewise.
* resolv/nss_dns/dns-network.c: Likewise.
* resolv/arpa/nameser.h: Update from Bind 8.2.2-P5.
* resolv/nsap_addr.c: Likewise.
* resolv/res_comp.c: Likewise.
* resolv/res_debug.c: Likewise.
* resolv/res_init.c: Likewise.
* resolv/res_mkquery.c: Likewise.
* resolv/res_query.c: Likewise.
* resolv/res_send.c: Likewise.
* resolv/resolv.h: Likewise.
* resolv/Versions: Add __res_state and __res_ninit with version
GLIBC_2.2 to libc.
Add new interfaces with version GLIBC_2.2 to libresolv.
* resolv/Banner: Update.
* include/arpa/nameser_compat.h: New file.
* resolv/ns_name.c: New file from Bind 8.2.2-P5.
* resolv/ns_netint.c: Likewise.
* resolv/ns_parse.c: Likewise.
* resolv/ns_print.c: Likewise.
* resolv/ns_samedomain.c: Likewise.
* resolv/ns_ttl.c: Likewise.
* resolv/arpa/nameser_compat.h: Likewise.
* resolv/res_debug.h: Likewise.
Some patches are based on work done by Adam D. Bradley
<artdodge@cs.bu.edu>.
* sysdeps/unix/sysv/linux/configure.in: Remove check for ldconfig,
set always use_ldconfig instead.