Linux Netfilter development
 help / color / mirror / Atom feed
From: Jeremy Sowden <jeremy@azazel.net>
To: Florian Westphal <fw@strlen.de>
Cc: Netfilter Devel <netfilter-devel@vger.kernel.org>
Subject: Re: [PATCH ulogd2 2/6] db, IP2BIN: correct `format_ipv6()` output buffer sizes
Date: Wed, 23 Apr 2025 12:51:53 +0100	[thread overview]
Message-ID: <20250423115153.GA349976@azazel.net> (raw)
In-Reply-To: <20250423112204.GA7371@breakpoint.cc>

[-- Attachment #1: Type: text/plain, Size: 1659 bytes --]

On 2025-04-23, at 13:22:04 +0200, Florian Westphal wrote:
> Jeremy Sowden <jeremy@azazel.net> wrote:
> > `format_ipv6()` formats IPv6 addresses as hex-strings.  However, sizing for the
> > output buffer is not done quite right.
> > 
> > `format_ipv6()` itself uses the size of `struct in6_addr` to verify that the
> > buffer size is large enough, and the output buffer for the call in util/db.c is
> > sized the same way.  However, the size that should be used is that of the
> > `s6_addr` member of `struct in6_addr`, not that of the whole structure.
> 
> ?
> 
> In what uinverse is sizeof(struct in6_addr) different from
> sizeof(((struct in6_addr) {}).s6_addr)?

A POSIX-compliant one? :)

	The <netinet/in.h> header shall define the in6_addr structure, which shall include at least the following member:

	  uint8_t s6_addr[16]

I dare say it's hair-splitting, but it's the size of the `s6_addr` member that
is significant, not the structure as a whole.

> > The elements of the `ipbin_array` array in ulogd_filter_IP2BIN.c are sized using
> > a local macro, `IPADDR_LENGTH`, which is defined as 128, the number of bits in
> > an IPv6 address; this is much larger than necessary.
> 
> Agreed.
> 
> > +#define FORMAT_IPV6_BUFSZ (2 + sizeof(((struct in6_addr) {}).s6_addr) * 2 + 1)
> 
> I'd prefer to not use the .s6_addr, its not needed.
> 
> > -		for (unsigned j = 0; i < sizeof(*ipv6); j += 4, i += 8) {
> > +		for (unsigned j = 0; i < sizeof(ipv6->s6_addr); j += 4, i += 8) {
> 
> I would leave this as-is.

Fair enough.

> First patch looks good, I'll apply it later today.  Still reviewing the
> rest.

J.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2025-04-23 11:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-20 17:20 [PATCH ulogd2 0/6] Add support for logging ARP packets Jeremy Sowden
2025-04-20 17:20 ` [PATCH ulogd2 1/6] IP2STR: correct address buffer size Jeremy Sowden
2025-04-20 17:20 ` [PATCH ulogd2 2/6] db, IP2BIN: correct `format_ipv6()` output buffer sizes Jeremy Sowden
2025-04-23 11:22   ` Florian Westphal
2025-04-23 11:51     ` Jeremy Sowden [this message]
2025-04-23 12:51       ` Florian Westphal
2025-04-20 17:20 ` [PATCH ulogd2 3/6] IP2HBIN, IP2STR: correct typo's Jeremy Sowden
2025-04-20 17:20 ` [PATCH ulogd2 4/6] IP2BIN, IP2HBIN, IP2STR: refactor `interp` call-backs Jeremy Sowden
2025-04-20 17:20 ` [PATCH ulogd2 5/6] Use `NFPROTO_*` constants for protocol families Jeremy Sowden
2025-04-20 17:20 ` [PATCH ulogd2 6/6] Add support for logging ARP packets Jeremy Sowden

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=20250423115153.GA349976@azazel.net \
    --to=jeremy@azazel.net \
    --cc=fw@strlen.de \
    --cc=netfilter-devel@vger.kernel.org \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox