public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: Danish Prakash <contact@danishpraka.sh>
Cc: passt-dev@passt.top
Subject: Re: [PATCH] pasta.c: modify hostname when detaching new namespace
Date: Mon, 29 Jul 2024 19:54:23 +0200	[thread overview]
Message-ID: <20240729195423.40f77811@elisabeth> (raw)
In-Reply-To: <65300ee2-aadf-4e72-b4e3-52909de5dbff@danishpraka.sh>

On Mon, 29 Jul 2024 19:26:28 +0530
Danish Prakash <contact@danishpraka.sh> wrote:

> Hi Stefano,
> 
> I was caught up with some work last month, hence the delay in responses
> since my last email.
> 
> On 5/24/24 11:09 PM, Stefano Brivio wrote:
> >> +		if (sethostname(hostname, strlen(hostname)))  
> > 
> > So, I mentioned before that you don't really need to set a NULL
> > terminating byte for sethostname() itself, because it takes a length.
> > 
> > But strlen() needs it. If gethostname() truncated the hostname,
> > according to POSIX, it's unspecified whether we'll have a NULL byte at
> > the end of 'hostname', and strlen() would read out-of-bounds, past the
> > end of 'hostname'.
> > 
> > That's not an issue with glibc, but if POSIX says it's not guaranteed,
> > we shouldn't take anything for granted.
> > 
> > I would suggest that you simply add a NULL byte at HOST_NAME_MAX,
> > unconditionally, that should cover the normal case as well as the
> > ENAMETOOLONG case. I haven't tested this by the way.  
> 
> Did you mean explicitly setting the NULL byte to `hostname`?
> 
>         hostname[HOST_NAME_MAX] = '\0';

Yes, exactly.

> Doing that after gethostname() and before sethostname() yields the
> desired result. I tested a few cases, seems to be fine.

Yes, I don't expect any difference with glibc, but better safe than
sorry (with other C libraries). Thanks.

-- 
Stefano


      reply	other threads:[~2024-07-29 17:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-20  8:35 [PATCH] pasta.c: modify hostname when detaching new namespace Danish Prakash
     [not found] ` <20240521193400.4f1b15c5@elisabeth>
2024-05-23 13:52   ` Danish Prakash
2024-05-23 14:23     ` Stefano Brivio
2024-05-24 12:45       ` Danish Prakash
2024-05-24 17:38         ` Stefano Brivio
2024-05-24 12:48 ` Danish Prakash
2024-05-24 17:39   ` Stefano Brivio
2024-06-25 22:27     ` Stefano Brivio
2024-07-29 13:56     ` Danish Prakash
2024-07-29 17:54       ` Stefano Brivio [this message]

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=20240729195423.40f77811@elisabeth \
    --to=sbrivio@redhat.com \
    --cc=contact@danishpraka.sh \
    --cc=passt-dev@passt.top \
    /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://passt.top/passt

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 IMAP folder(s).