Expected outcome of passing null *name ptr to ares_getaddrinfo()

Peter Pentchev roam at ringlet.net
Thu Mar 14 18:50:41 CET 2024


On Wed, Mar 13, 2024 at 04:39:59PM -0700, Carson Vandegriffe via c-ares wrote:
> Hi all,
> 
> I've been working on an effort to override some (libc) /getaddrinfo()/ calls
> into /ares_getaddrinfo()/ calls (see recent mail regarding LD_PRELOAD). I
> notice that in some cases, /getaddrinfo()/ is getting passed a null /node/
> pointer. In the docs for the function, it states that:
> 
> "Either/node/  or/service/, but not both, may be NULL."
> 
> and that:
> 
> "If/node/  is NULL, then the network address will be set to the loopback interface address ..."
> 
> 
> Now in the /ares_getaddrinfo() /docs, the equivalent behavior of passing in
> a null /name/ pointer is undefined. And I'm seeing the following segfault
> splat when a null /name/ pointer is used:
> 
> #0  __strchr_avx2 () at ../sysdeps/x86_64/multiarch/strchr-avx2.S:65
> #1  0x00007f3e02488848 in ares__single_domain (channel=0x1daa7f0, name=0x0, s=0x7ffc98f50608) at ares_search.c:288
> #2  0x00007f3e0247ec49 in ares_getaddrinfo_int (channel=0x1daa7f0, name=0x0, service=0x7ffc98f50912 "5201",
>     hints=0x7ffc98f507e0, callback=0x7f3e0266a376 <ai_callback>, arg=0x7ffc98f50918) at ares_getaddrinfo.c:568
> #3  0x00007f3e0247f14e in ares_getaddrinfo (channel=0x1daa7f0, name=0x0, service=0x7ffc98f50912 "5201",
>     hints=0x7ffc98f507e0, callback=0x7f3e0266a376 <ai_callback>, arg=0x7ffc98f50918) at ares_getaddrinfo.c:681
> #4  0x00007f3e0266a9fb in getaddrinfo (libc_node=0x0, libc_service=0x7ffc98f50912 "5201", libc_hints=0x7ffc98f50920,
>     libc_res=0x7ffc98f50918) at intercept.c:158
> 
> So I was curious, what is the expected behavior when a null /name/ pointer
> is passed into /ares_getaddrinfo()/?

My guess would be that if the documentation does not explicitly say that
you are allowed to pass a null pointer, then you are *not* supposed to
pass a null pointer, and things will break if you do.

G'luck,
Peter

-- 
Peter Pentchev  roam at ringlet.net roam at debian.org pp at storpool.com
PGP key:        http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.haxx.se/pipermail/c-ares/attachments/20240314/ec0e9b15/attachment.sig>


More information about the c-ares mailing list