Bug 27634 - getnameinfo on abstract socket fails to populate serv with a name
Summary: getnameinfo on abstract socket fails to populate serv with a name
Status: UNCONFIRMED
Alias: None
Product: glibc
Classification: Unclassified
Component: network (show other bugs)
Version: 2.34
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-03-23 11:16 UTC by daniel@mariadb.org
Modified: 2021-03-27 05:32 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description daniel@mariadb.org 2021-03-23 11:16:42 UTC
gni_serv_local uses checked_copy which uses memcpy to create the destination name derived from strlen.

With abstract sockets however the serv starts with '\0', according to unix(7) can contain '\0'. This leads to a rather serv description.

Its hard to say what the desired behavior is as the serv is a null string on the API.

A memcpy of the real length is probably a start.


My solution currently has some assumptions (however its good enough for me).

      getnameinfo_err= getnameinfo(&addr.sa, addrlen, hbuf, sizeof(hbuf), sbuf,
                                   sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV);
      if (getnameinfo_err)
        sql_print_warning("getnameinfo() on systemd socket activation socket %d"
                          " failed with error %d", fd, getnameinfo_err);
      else
      {
        /* handle abstract sockets and present them in @ form */
        if (sbuf[0] == '\0')
          addr.un.sun_path[0] = '@';
        sql_print_information("Using systemd activated socket %s port %s", hbuf,
                       sbuf[0] == '\0' ? addr.un.sun_path : sbuf);
      }
Comment 1 daniel@mariadb.org 2021-03-24 00:12:31 UTC
A memcpy of the real length could simply the (at least my) user space code to:

        if (sbuf[0] == '\0')
          sbuf[0] = '@';

The use of this buffer has some assumptions about if other nulls are in the sun_path buffer.

The length of this in memcpy can be derived from the argument addrlen - offsetof(struct sockaddr_un, sun_path).

A manual page document document using this as the length if sbuf[0] = '\0' could be useful in allowing a more fully featured use in userspace for this edge case.

Both of these changes, it should be able to use the serv/sbuf with abstract sockets, despite detracting a bit in the interface from the protocol independence it aimed to provide.
Comment 2 daniel@mariadb.org 2021-03-27 05:32:40 UTC
patch: https://sourceware.org/pipermail/libc-alpha/2021-March/124459.html

disclaimer form requested.