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

Carson Vandegriffe carson.vandegriffe at candelatech.com
Sat Mar 16 22:06:08 CET 2024


Thanks Cristian,

You're right, it's the POSIX function that I was meaning to reference.

I've opted to intercept the null pointer issue in my wrapper function, 
for now:

@@ -116,6 +116,17 @@ int getaddrinfo(const char *restrict libc_node,
      if (name_override && name_override[0] != '\0') {
          libc_node = name_override;
      }
+    if (libc_node == NULL) {
+        // replace with empty address str, as null ptr is not handled by ares_getaddrinfo()
+        if (hints.ai_family == AF_INET) {
+            libc_node = "0.0.0.0";
+        } else {
+            libc_node = "::";
+        }
+        if (getenv("DEBUG")) {
+            fprintf(stderr, __FILE__ ":%d Replaced the null libc_node arg with '%s'.\n", __LINE__, libc_node);
+        }
+    }
      const char* local_dev_name = getenv("LOCAL_DEV");
      if (local_dev_name) {
          // requires root privileges, failure to apply is silently ignored

Which functions as desired. And I plan to propose a null-handling patch 
for ares_getaddrinfo() soon.

Best,
Carson

On 3/14/24 11:35 AM, Cristian Rodríguez wrote:
> On Thu, Mar 14, 2024 at 3:37 AM Carson Vandegriffe via c-ares
> <c-ares at lists.haxx.se>  wrote:
>> Hi all,
>>
>> I've been working on an effort to override some (libc) getaddrinfo()
> It is  POSIX that you have to quote.. not the libc manual..
>
> "If nodename is not null, the requested service location is named by
> nodename; otherwise, the requested service location is local to the
> caller."
>
> It is a bug whatever interpretation is made.. fill a bug report.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.haxx.se/pipermail/c-ares/attachments/20240316/dd87fa12/attachment.htm>


More information about the c-ares mailing list