aboutsummaryrefslogtreecommitdiff
path: root/resolv/res_send.c
AgeCommit message (Collapse)AuthorFilesLines
2024-07-24resolv: Track single-request fallback via _res._flags (bug 31476)Florian Weimer1-5/+7
This avoids changing _res.options, which inteferes with change detection as part of automatic reloading of /etc/resolv.conf. Reviewed-by: DJ Delorie <dj@redhat.com> (cherry picked from commit 868ab8923a2ec977faafec97ecafac0c3159c1b2)
2024-07-24resolv: Do not wait for non-existing second DNS response after error (bug 30081)Florian Weimer1-1/+1
In single-request mode, there is no second response after an error because the second query has not been sent yet. Waiting for it introduces an unnecessary timeout. Reviewed-by: DJ Delorie <dj@redhat.com> (cherry picked from commit af625987d619388a100b153520d3ee308bda9889)
2024-07-24resolv: Allow short error responses to match any query (bug 31890)Florian Weimer1-10/+19
Reviewed-by: DJ Delorie <dj@redhat.com> (cherry picked from commit 691a3b2e9bfaba842e46a5ccb7f5e6ea144c3ade)
2024-01-01Update copyright dates with scripts/update-copyrightsPaul Eggert1-1/+1
2023-01-06Update copyright dates with scripts/update-copyrightsJoseph Myers1-1/+1
2022-06-24resolv: Implement no-aaaa stub resolver optionFlorian Weimer1-2/+7
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2022-03-22resolv: Fix unaligned accesses to fields in HEADER structJohn David Anglin1-9/+9
The structure HEADER is normally aligned to a word boundary but sometimes it needs to be accessed when aligned on a byte boundary. This change defines a new typedef, UHEADER, with alignment 1. It is used to ensure the fields are accessed with byte loads and stores when necessary. V4: Change to res_mkquery.c deleted. Small whitespace fix. V5: Move UHEADER typedef to resolv/resolv-internal.h. Replace all HEADER usage with UHEADER in resolv/res_send.c. Signed-off-by: John David Anglin <dave.anglin@bell.net> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2022-01-01Update copyright dates with scripts/update-copyrightsPaul Eggert1-1/+1
I used these shell commands: ../glibc/scripts/update-copyrights $PWD/../gnulib/build-aux/update-copyright (cd ../glibc && git commit -am"[this commit message]") and then ignored the output, which consisted lines saying "FOO: warning: copyright statement not found" for each of 7061 files FOO. I then removed trailing white space from math/tgmath.h, support/tst-support-open-dev-null-range.c, and sysdeps/x86_64/multiarch/strlen-vec.S, to work around the following obscure pre-commit check failure diagnostics from Savannah. I don't know why I run into these diagnostics whereas others evidently do not. remote: *** 912-#endif remote: *** 913: remote: *** 914- remote: *** error: lines with trailing whitespace found ... remote: *** error: sysdeps/unix/sysv/linux/statx_cp.c: trailing lines
2021-07-19resolv: Move res_send, res_nsend into libcFlorian Weimer1-21/+33
Switch to public symbols without __ prefix (due to improved namespace management). __res_send, __res_nsend were moved using the script (with --no-new-version). res_send@@GLIBC_2.34 and res_nsend@@GLIBC_2.34 were added using make update-all-abi. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2021-07-19resolv: Move res_queriesmatch to its own file and into libcFlorian Weimer1-59/+6
And reformat it to GNU style. The treatment of this function matches res_nameinquery, for the reasons stated there. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2021-07-19resolv: Move res_nameinquery to its own file and into libcFlorian Weimer1-42/+1
And reformat to GNU style. This deprecated function is used in the implementation of the stub resolver (for now). Keep the public symbol in libresolv for now (so that no new symbol version is needed), and add a forwarder to libresolv. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2021-07-19resolv: Move ns_samename into its own file, and into libcFlorian Weimer1-2/+2
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>
2021-07-19resolv: Move res_isourserver to its own file and reformat to GNU styleFlorian Weimer1-51/+0
Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2021-07-19resolv: Move __res_get_nsaddr to its own file and into libcFlorian Weimer1-21/+4
Eliminate the use of the EXT macro from it because it does not add clarity. The function was added to res_send.c in 2015, and the copyright year reflects that. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2021-07-19resolv: Move dn_expand to its own file and into libcFlorian Weimer1-2/+2
And reformat to GNU style. This switches back to the dn_expand name for the ABI symbol and turns __dn_expand into a compatibility symbol. With the improved namespace management in current glibc, it is no longer necessary to use a private namespace symbol. To avoid old code binding to a GLIBC_PRIVATE symbol by accident, use __libc_dn_expand for the internal symbol name. The symbols dn_expand, __dnexpand were moved using scripts/move-symbol-to-libc.py, followed by an adjustment to make dn_expand the only GLIBC_2.34 symbol. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2021-07-15resolv: Remove unnecessary res_isourserver_p call from send_dgFlorian Weimer1-6/+0
As the comment indicates, the check is unnecessary due to the way the UDP socket is set up. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2021-01-02Update copyright dates with scripts/update-copyrightsPaul Eggert1-1/+1
I used these shell commands: ../glibc/scripts/update-copyrights $PWD/../gnulib/build-aux/update-copyright (cd ../glibc && git commit -am"[this commit message]") and then ignored the output, which consisted lines saying "FOO: warning: copyright statement not found" for each of 6694 files FOO. I then removed trailing white space from benchtests/bench-pthread-locks.c and iconvdata/tst-iconv-big5-hkscs-to-2ucs4.c, to work around this diagnostic from Savannah: remote: *** pre-commit check failed ... remote: *** error: lines with trailing whitespace found remote: error: hook declined to update refs/heads/master
2020-10-14resolv: Handle transaction ID collisions in parallel queries (bug 26600)Florian Weimer1-20/+20
If the transaction IDs are equal, the old check attributed both responses to the first query, not recognizing the second response. This fixes bug 26600.
2020-01-20Get rid of Werror=maybe-uninitialized in res_send.c.Stefan Liebler1-0/+4
The commit 446997ff1433d33452b81dfa9e626b8dccf101a4 introduced this new usage of resplen. If build with gcc 9 -march>=z13 on s390x, the following warning occurs: res_send.c: In function ‘__res_context_send’: res_send.c:539:6: error: ‘resplen’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 539 | if (resplen > HFIXEDSZ) | ^ Therefore this patch adds a further DIAG_IGNORE_NEEDS_COMMENT in the same way as it was previously done for usages of resplen or n. See commit d1bc2cbbed9aea2017ef941f63c8786571da5b4f.
2020-01-01Update copyright dates with scripts/update-copyrights.Joseph Myers1-1/+1
2019-11-27resolv: Implement trust-ad option for /etc/resolv.conf [BZ #20358]Florian Weimer1-0/+21
This introduces a concept of trusted name servers, for which the AD bit is passed through to applications. For untrusted name servers (the default), the AD bit in responses are cleared, to provide a safe default. This approach is very similar to the one suggested by Pavel Šimerda in <https://bugzilla.redhat.com/show_bug.cgi?id=1164339#c15>. The DNS test framework in support/ is enhanced with support for setting the AD bit in responses. Tested on x86_64-linux-gnu. Change-Id: Ibfe0f7c73ea221c35979842c5c3b6ed486495ccc
2019-10-30Change most internal uses of __gettimeofday to __clock_gettime.Zack Weinberg1-6/+1
Since gettimeofday will shortly be implemented in terms of clock_gettime on all platforms, internal code should use clock_gettime directly; in addition to removing a layer of indirection, this will allow us to remove the PLT-bypass gunk for gettimeofday. (We can't quite do that yet, but it'll be coming later in this patch series.) In many cases, the changed code does fewer conversions. The changed code always assumes __clock_gettime (CLOCK_REALTIME) cannot fail. Most of the call sites were assuming gettimeofday could not fail, but a few places were checking for errors. POSIX says clock_gettime can only fail if the clock constant is invalid or unsupported, and CLOCK_REALTIME is the one and only clock constant that's required to be supported. For consistency I grepped the entire source tree for any other places that checked for errors from __clock_gettime (CLOCK_REALTIME), found one, and changed it too. (For the record, POSIX also says gettimeofday can never fail.) (It would be nice if we could declare that GNU systems will always support CLOCK_MONOTONIC as well as CLOCK_REALTIME; there are several places where we are using CLOCK_REALTIME where _MONOTONIC would be more appropriate, and/or trying to use _MONOTONIC and then falling back to _REALTIME. But the Hurd doesn't support CLOCK_MONOTONIC yet, and it looks like adding it would involve substantial changes to gnumach's internals and API. Oh well.) A few Hurd-specific files were changed to use __host_get_time instead of __clock_gettime, as this seemed tidier. We also assume this cannot fail. Skimming the code in gnumach leads me to believe the only way it could fail is if __mach_host_self also failed, and our Hurd-specific code consistently assumes that can't happen, so I'm going with that. With the exception of support/support_test_main.c, test cases are not modified, mainly because I didn't want to have to figure out which test cases were testing gettimeofday specifically. The definition of GETTIME in sysdeps/generic/memusage.h had a typo and was not reading tv_sec at all. I fixed this. It appears nobody has been generating malloc traces on a machine that doesn't have a superseding definition. There are a whole bunch of places where the code could be simplified by factoring out timespec subtraction and/or comparison logic, but I want to keep this patch as mechanical as possible. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu, powerpc64-linux-gnu, powerpc-linux-gnu, and aarch64-linux-gnu. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org> Reviewed-by: Lukasz Majewski <lukma@denx.de>
2019-09-07Prefer https to http for gnu.org and fsf.org URLsPaul Eggert1-1/+1
Also, change sources.redhat.com to sourceware.org. This patch was automatically generated by running the following shell script, which uses GNU sed, and which avoids modifying files imported from upstream: sed -ri ' s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g ' \ $(find $(git ls-files) -prune -type f \ ! -name '*.po' \ ! -name 'ChangeLog*' \ ! -path COPYING ! -path COPYING.LIB \ ! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \ ! -path manual/texinfo.tex ! -path scripts/config.guess \ ! -path scripts/config.sub ! -path scripts/install-sh \ ! -path scripts/mkinstalldirs ! -path scripts/move-if-change \ ! -path INSTALL ! -path locale/programs/charmap-kw.h \ ! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \ ! '(' -name configure \ -execdir test -f configure.ac -o -f configure.in ';' ')' \ ! '(' -name preconfigure \ -execdir test -f preconfigure.ac ';' ')' \ -print) and then by running 'make dist-prepare' to regenerate files built from the altered files, and then executing the following to cleanup: chmod a+x sysdeps/unix/sysv/linux/riscv/configure # Omit irrelevant whitespace and comment-only changes, # perhaps from a slightly-different Autoconf version. git checkout -f \ sysdeps/csky/configure \ sysdeps/hppa/configure \ sysdeps/riscv/configure \ sysdeps/unix/sysv/linux/csky/configure # Omit changes that caused a pre-commit check to fail like this: # remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines git checkout -f \ sysdeps/powerpc/powerpc64/ppc-mcount.S \ sysdeps/unix/sysv/linux/s390/s390-64/syscall.S # Omit change that caused a pre-commit check to fail like this: # remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-07-02Fix build warnings in resolv/res_send.cStefan Liebler1-1/+16
This patch fixes the gcc warnings seen with gcc 9 -march>=z13 on s390x: res_send.c: In function ‘__res_context_send’: res_send.c:498:7: error: ‘resplen’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 498 | if (n == 0 && (buf2 == NULL || *resplen2 == 0)) | ^ In this case send_vc is inlined into __res_context_send and the maybe uninitialized resplen belongs to the one in send_vc. In send_vc there is already a DIAG_IGNORE_NEEDS_COMMENT (5, "-Wmaybe-uninitialized") and a comment which explains that this is a false-positive. Note that resplen is used as return value. This patch adds a further DIAG_IGNORE_NEEDS_COMMENT around the declaration of n in __res_context_send and the comparison after n was set to the return value of send_vc. ChangeLog: * resolv/res_send.c (__res_context_send): Disable maybe-uninitialized warning.
2019-04-08resolv: Remove RES_INSECURE1, RES_INSECURE2Florian Weimer1-19/+13
Always perform the associated security checks.
2019-03-22Do not use HP_TIMING_NOW for random bitsAdhemerval Zanella1-10/+2
This patch removes the HP_TIMING_BITS usage for fast random bits and replace with clock_gettime (CLOCK_MONOTONIC). It has unspecified starting time and nano-second accuracy, so its randomness is significantly better than gettimeofday. Althoug it should incur in more overhead (specially for architecture that support hp-timing), the symbol is also common implemented as a vDSO. Checked on aarch64-linux-gnu, x86_64-linux-gnu, and i686-linux-gnu. I also checked on a i686-gnu build. * include/random-bits.h: New file. * resolv/res_mkquery.c [HP_TIMING_AVAIL] (RANDOM_BITS, (__res_context_mkquery): Remove usage hp-timing usage and replace with random_bits. * resolv/res_send.c [HP_TIMING_AVAIL] (nameserver_offset): Likewise. * sysdeps/posix/tempname.c [HP_TIMING_AVAIL] (__gen_tempname): Likewise.
2019-03-12resolv: Enable full ICMP errors for UDP DNS sockets [BZ #24047]Florian Weimer1-0/+12
The Linux kernel suppresses some ICMP error messages by default for UDP sockets. This commit enables full ICMP error reporting, hopefully resulting in faster failover to working name servers.
2019-01-01Update copyright dates with scripts/update-copyrights.Joseph Myers1-1/+1
* All files with FSF copyright notices: Update copyright dates using scripts/update-copyrights. * locale/programs/charmap-kw.h: Regenerated. * locale/programs/locfile-kw.h: Likewise.
2018-05-17Remove unneeded setting of errno after malloc failureAndreas Schwab1-4/+1
The errno value has alread been set by malloc.
2018-04-09resolv: Fully initialize struct mmsghdr in send_dg [BZ #23037]Florian Weimer1-19/+21
2018-03-27Fix crash in resolver on memory allocation failure (bug 23005)Andreas Schwab1-0/+5
2018-01-01Update copyright dates with scripts/update-copyrights.Joseph Myers1-1/+1
* All files with FSF copyright notices: Update copyright dates using scripts/update-copyrights. * locale/programs/charmap-kw.h: Regenerated. * locale/programs/locfile-kw.h: Likewise.
2017-07-03resolv: Introduce struct resolv_context [BZ #21668]Florian Weimer1-13/+31
struct resolv_context objects provide a temporary resolver context which does not change during a name lookup operation. Only when the outmost context is created, the stub resolver configuration is verified to be current (at present, only against previous res_init calls). Subsequent attempts to obtain the context will reuse the result of the initial verification operation. struct resolv_context can also be extended in the future to store data which needs to be deallocated during thread cancellation.
2017-06-30resolv: Move res_isourserver, res_send from res_data.c to res_send.cFlorian Weimer1-0/+15
2017-06-30resolv: Remove DEBUG from resolv/res_send.cFlorian Weimer1-144/+1
2017-06-30resolv: Make RES_ROTATE start with a random name server [BZ #19570]Florian Weimer1-28/+72
Do not copy the actual name server addresses to rotate them. Use a global rotation offset instead.
2017-04-19resolv: Replace __builtin_expect with __glibc_unlikely/__glibc_likelyFlorian Weimer1-1/+1
2017-04-19Create more sockets with SOCK_CLOEXEC [BZ #15722]Florian Weimer1-5/+8
2017-04-13resolv: Remove EDNS fallback [BZ #21369]Florian Weimer1-20/+0
EDNS is disabled by default (so there is interoperability issue), and the fallback code is problematic because it prevents an application from obtaining DNSSEC data after a FORMERR response.
2017-04-13resolv: Remove internal and unused definitions from <resolv.h>Florian Weimer1-1/+1
The RES_F_* constants are only used with the private _res._flags member. RES_EXHAUSTIVE is unused. The removed function declarations refer to functions not actually exported by glibc, so they are unusable by applications.
2017-03-01Narrowing the visibility of libc-internal.h even further.Zack Weinberg1-1/+1
posix/wordexp-test.c used libc-internal.h for PTR_ALIGN_DOWN; similar to what was done with libc-diag.h, I have split the definitions of cast_to_integer, ALIGN_UP, ALIGN_DOWN, PTR_ALIGN_UP, and PTR_ALIGN_DOWN to a new header, libc-pointer-arith.h. It then occurred to me that the remaining declarations in libc-internal.h are mostly to do with early initialization, and probably most of the files including it, even in the core code, don't need it anymore. Indeed, only 19 files actually need what remains of libc-internal.h. 23 others need libc-diag.h instead, and 12 need libc-pointer-arith.h instead. No file needs more than one of them, and 16 don't need any of them! So, with this patch, libc-internal.h stops including libc-diag.h as well as losing the pointer arithmetic macros, and all including files are adjusted. * include/libc-pointer-arith.h: New file. Define cast_to_integer, ALIGN_UP, ALIGN_DOWN, PTR_ALIGN_UP, and PTR_ALIGN_DOWN here. * include/libc-internal.h: Definitions of above macros moved from here. Don't include libc-diag.h anymore either. * posix/wordexp-test.c: Include stdint.h and libc-pointer-arith.h. Don't include libc-internal.h. * debug/pcprofile.c, elf/dl-tunables.c, elf/soinit.c, io/openat.c * io/openat64.c, misc/ptrace.c, nptl/pthread_clock_gettime.c * nptl/pthread_clock_settime.c, nptl/pthread_cond_common.c * string/strcoll_l.c, sysdeps/nacl/brk.c * sysdeps/unix/clock_settime.c * sysdeps/unix/sysv/linux/i386/get_clockfreq.c * sysdeps/unix/sysv/linux/ia64/get_clockfreq.c * sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c * sysdeps/unix/sysv/linux/sparc/sparc64/get_clockfreq.c: Don't include libc-internal.h. * elf/get-dynamic-info.h, iconv/loop.c * iconvdata/iso-2022-cn-ext.c, locale/weight.h, locale/weightwc.h * misc/reboot.c, nis/nis_table.c, nptl_db/thread_dbP.h * nscd/connections.c, resolv/res_send.c, soft-fp/fmadf4.c * soft-fp/fmasf4.c, soft-fp/fmatf4.c, stdio-common/vfscanf.c * sysdeps/ieee754/dbl-64/e_lgamma_r.c * sysdeps/ieee754/dbl-64/k_rem_pio2.c * sysdeps/ieee754/flt-32/e_lgammaf_r.c * sysdeps/ieee754/flt-32/k_rem_pio2f.c * sysdeps/ieee754/ldbl-128/k_tanl.c * sysdeps/ieee754/ldbl-128ibm/k_tanl.c * sysdeps/ieee754/ldbl-96/e_lgammal_r.c * sysdeps/ieee754/ldbl-96/k_tanl.c, sysdeps/nptl/futex-internal.h: Include libc-diag.h instead of libc-internal.h. * elf/dl-load.c, elf/dl-reloc.c, locale/programs/locarchive.c * nptl/nptl-init.c, string/strcspn.c, string/strspn.c * malloc/malloc.c, sysdeps/i386/nptl/tls.h * sysdeps/nacl/dl-map-segments.h, sysdeps/x86_64/atomic-machine.h * sysdeps/unix/sysv/linux/spawni.c * sysdeps/x86_64/nptl/tls.h: Include libc-pointer-arith.h instead of libc-internal.h. * elf/get-dynamic-info.h, sysdeps/nacl/dl-map-segments.h * sysdeps/x86_64/atomic-machine.h: Add multiple include guard.
2017-01-01Update copyright dates with scripts/update-copyrights.Joseph Myers1-1/+1
2016-12-31resolv: Deprecate RES_BLASTFlorian Weimer1-2/+1
2016-12-27Fix typos in the spelling of "implementation"Dmitry V. Levin1-1/+1
Apply the following spelling fix: $ git grep -El 'implemetn?ation' | xargs sed -ri 's/implemetn?ation/implementation/g' [BZ #19514] * resolv/res_send.c: Fix typo in comment. * sysdeps/i386/i386-mcount.S: Likewise. * sysdeps/s390/s390-32/s390-mcount.S: Likewise. * sysdeps/s390/s390-64/s390x-mcount.S: Likewise. * sysdeps/sparc/sparc-mcount.S: Likewise.
2016-11-02Bug 20729: Fix build failures on ppc64 and other arches.Carlos O'Donell1-2/+2
The changes to fix bug 20729 introduced an error which removed an ignore diagnostic from -O2 by using the new -Os related macro. This broke ppc64 builds. This commit fixes the mistake. Tested on x86, x86_64, ppc64, ppc64le, arm, aarch64, and s390x.
2016-10-29Bug 20729: Fix building with -Os.Carlos O'Donell1-1/+10
This commit adds a new DIAG_IGNORE_Os_NEEDS_COMMENT which is only enabled when compiling with -Os. This allows developers working on -Os enabled builds to mark false-positive warnings without impacting the warnings emitted at -O2. Then using the new DIAG_IGNORE_Os_NEEDS_COMMENT we fix 6 warnings generated with GCC 5 to get -Os builds working again.
2016-09-21resolv: Remove unsupported hook functions from the API [BZ #20016]Florian Weimer1-85/+0
2016-04-28resolv: Remove SCCS and RCS keywordsFlorian Weimer1-5/+0
2016-04-27resolv: Always set *resplen2 out parameter in send_vc [BZ #19825]Florian Weimer1-21/+18
In various error scenarios (for example, if the server closes the TCP connection before sending the full response), send_vc can return without resetting the *resplen2 value. This can pass uninitialized or unexpected data to the caller.
2016-03-25resolv: Always set *resplen2 out parameter in send_dg [BZ #19791]Florian Weimer1-23/+40
Since commit 44d20bca52ace85850012b0ead37b360e3ecd96e (Implement second fallback mode for DNS requests), there is a code path which returns early, before *resplen2 is initialized. This happens if the name server address is immediately recognized as invalid (because of lack of protocol support, or if it is a broadcast address such 255.255.255.255, or another invalid address). If this happens and *resplen2 was non-zero (which is the case if a previous query resulted in a failure), __libc_res_nquery would reuse an existing second answer buffer. This answer has been previously identified as unusable (for example, it could be an NXDOMAIN response). Due to the presence of a second answer, no name server switching will occur. The result is a name resolution failure, although a successful resolution would have been possible if name servers have been switched and queries had proceeded along the search path. The above paragraph still simplifies the situation. Before glibc 2.23, if the second answer needed malloc, the stub resolver would still attempt to reuse the second answer, but this is not possible because __libc_res_nsearch has freed it, after the unsuccessful call to __libc_res_nquerydomain, and set the buffer pointer to NULL. This eventually leads to an assertion failure in __libc_res_nquery: /* Make sure both hp and hp2 are defined */ assert((hp != NULL) && (hp2 != NULL)); If assertions are disabled, the consequence is a NULL pointer dereference on the next line. Starting with glibc 2.23, as a result of commit e9db92d3acfe1822d56d11abcea5bfc4c41cf6ca (CVE-2015-7547: getaddrinfo() stack-based buffer overflow (Bug 18665)), the second answer is always allocated with malloc. This means that the assertion failure happens with small responses as well because there is no buffer to reuse, as soon as there is a name resolution failure which triggers a search for an answer along the search path. This commit addresses the issue by ensuring that *resplen2 is initialized before the send_dg function returns. This commit also addresses a bug where an invalid second reply is incorrectly returned as a valid to the caller.