[PATCH] inet: getnameinfo fix serv for abstract socket [BZ #27634]
Florian Weimer
fw@deneb.enyo.de
Sat Mar 27 18:57:35 GMT 2021
* Daniel Black:
> @@ -459,6 +459,15 @@ gni_serv_local (struct scratch_buffer *tmpbuf,
> const struct sockaddr *sa, socklen_t addrlen,
> char *serv, socklen_t servlen, int flags)
> {
> + if (((const struct sockaddr_un *) sa)->sun_path[0] == '\0')
> + {
> + /* Abstract socket */
> + socklen_t len = addrlen - offsetof (struct sockaddr_un, sun_path);
> + if (len > servlen)
> + return EAI_OVERFLOW;
> + memcpy (serv, ((const struct sockaddr_un *) sa)->sun_path, len);
> + return 0;
> + }
> return checked_copy
> (serv, servlen, ((const struct sockaddr_un *) sa)->sun_path);
> }
Is this really useful as an interface? The caller would still have to
know the struct sockaddr_un layout to figure out the length. So it
could just struct sockaddr_un directly.
In general, getnameinfo itself is not very portable when applied to
AF_UNIX addresses. Not all systems that have AF_UNIX also implement
it for getnameinfo. How the path is mapped between the host and
service names also differs. Therefore, I think applications should
look for AF_UNIX addresses directly. There is also no string
transformation needed, unlike for the other address families.
More information about the Libc-alpha
mailing list