mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Markus Wichmann <nullplan@gmx.net>
To: musl@lists.openwall.com
Subject: Re: [musl] AF_LOCAL
Date: Sun, 10 Jul 2022 20:06:51 +0200	[thread overview]
Message-ID: <20220710180651.GC2522@voyager> (raw)
In-Reply-To: <CANs4VLxjt0bpn4ENkkVQerfML7y=BY4xT1UA=a3yxah8mm9iuA@mail.gmail.com>

On Sun, Jul 10, 2022 at 04:32:51PM +0200, Tomasz Duda wrote:
> Hi,
>
> I'm using
> python:3.9-alpine3.14
> It looks that AF_LOCAL is not implemented.
> It would be nice if you could include it.
>
> BR,
> TD
>

It would have been nice to mention you mean getnameinfo(). I wonder if
this is even valid, since you cannot call getaddrinfo() with the node
and service gained from here and get the socket address back out. I
skimmed POSIX on these functions but could not identify if adding
AF_LOCAL is OK.

> diff --git a/src/network/getnameinfo.c b/src/network/getnameinfo.c
> index 949e181..7d3a9c3 100644
> --- a/src/network/getnameinfo.c
> +++ b/src/network/getnameinfo.c
> @@ -11,7 +11,9 @@
> #include <resolv.h>
> #include "lookup.h"
> #include "stdio_impl.h"
> +#include <sys/un.h>
> +#define MIN(a,b) ((a)<(b) ? (a) : (b))
> #define PTR_MAX (64 + sizeof ".in-addr.arpa")
> #define RR_PTR 12
> @@ -118,6 +120,29 @@ static int dns_parse_callback(void *c, int rr, const
> void *data, int len, const
> }
> +/*
> + * getnameinfo_local():
> + * Format an local address into a printable format.
> + */

What is this? Documentation comments are not present anywhere else in
the code.

> +/* ARGSUSED */

What is this? I've seen these comments before, and they are usually used
to silence some kind of linter. But again, these are not used anywhere
else in the code.

> +static int
> +getnameinfo_local(const struct sockaddr *sa, socklen_t salen,
> + char *host, socklen_t hostlen, char *serv, socklen_t servlen,
> + int flags __attribute__((unused)))

We generally don't use GCC attributes unless we can help it. In this
case there is no reason for the attribute, but neither is there for the
argument. You could just drop it.

> +{
> + const struct sockaddr_un *sun =
> + (const struct sockaddr_un *)(const void *)sa;

Why the two conversions? Wouldn't either one suffice?

> + if (salen < (socklen_t) offsetof(struct sockaddr_un, sun_path)) {
> + return EAI_FAMILY;
> + }
> + if (serv != NULL && servlen > 0)
> + serv[0] = '\0';
> + if (host && hostlen > 0)
> + strncpy(host, sun->sun_path,
> + MIN((socklen_t) sizeof(sun->sun_path) + 1, hostlen));
> + return 0;
> +}
> +

The sizeof expression is invalid; the size of the path field is
salen - offsetof(struct sockaddr_un, sun_path). The + 1 is invalid as
well (sizeof already gives you the maximum, anyway, you cannot validly
go beyond it). And the construction ignores abstract addresses (first
path byte is zero, then the name is whatever octets follow, for however
much the length given is).

Ciao,
Markus

  reply	other threads:[~2022-07-10 18:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-10 14:32 Tomasz Duda
2022-07-10 18:06 ` Markus Wichmann [this message]
2022-07-11  4:48 ` Florian Weimer
2022-07-11  7:54   ` Tomasz Duda
2022-07-11  7:56     ` Florian Weimer
2022-07-11  8:04       ` Tomasz Duda
2022-07-11 15:22         ` Rich Felker
2022-07-11 19:53           ` Tomasz Duda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220710180651.GC2522@voyager \
    --to=nullplan@gmx.net \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).