From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-06.pe-a.jellyfish.systems (out-06.pe-a.jellyfish.systems [198.54.127.66]) by passt.top (Postfix) with ESMTPS id 762C65A004E for ; Mon, 29 Jul 2024 15:56:40 +0200 (CEST) Received: from output-router-d5c465c44-45n78 (new-01-3.privateemail.com [66.29.159.56]) by pe-a.jellyfish.systems (Postfix) with ESMTPA id 4WXfzV3QNVz4wPS; Mon, 29 Jul 2024 13:56:38 +0000 (UTC) Received: from MTA-09.privateemail.com (unknown [10.50.14.19]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by NEW-01-3.privateemail.com (Postfix) with ESMTPS id 683261005889; Mon, 29 Jul 2024 09:56:38 -0400 (EDT) Received: from mta-09.privateemail.com (localhost [127.0.0.1]) by mta-09.privateemail.com (Postfix) with ESMTP id 38A0D18000E2; Mon, 29 Jul 2024 09:56:38 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=danishpraka.sh; s=default; t=1722261398; bh=6MGnPOvSk0IklCLIdfq8fhWT/TAO0uJPdJ2RYa7Fh5U=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=pE4QKa4fQrdWr18HNr10dSkjEZGHc9FaCMijpRNVrw1LoAZR6FDAChvfETaP6dKdd tOujxJY3A3BEAjb2KVNUmo1q6KRls6cNX69qo3T2DZCtHu3EvQefmmrFv1QS4SPzFb HCGoEajjWldb4CZw3BPdz8UPtxpBVOSkkU9N1PpP2ZpdHIFUbLfiIUZ95mo57b7xvb ZV0Vgx1ziGWqYdPNSJuJdWxXDrwzRT1Ehs0OQp90kmokrjsTQp3c6xABpdOpgJerqB p0/icFRKJ+TJwsueD/ExoB356U19/N/ogLjeqc1ikHuWLDkbAkNtDz2d0A6y7ugKKT 8Qn00VxWJsx+Q== Received: from [192.168.1.28] (unknown [122.171.20.208]) by mta-09.privateemail.com (Postfix) with ESMTPA; Mon, 29 Jul 2024 09:56:35 -0400 (EDT) Message-ID: <65300ee2-aadf-4e72-b4e3-52909de5dbff@danishpraka.sh> Date: Mon, 29 Jul 2024 19:26:28 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] pasta.c: modify hostname when detaching new namespace To: Stefano Brivio References: <20240520083650.12032-1-contact@danishpraka.sh> <20240524124903.2004-1-contact@danishpraka.sh> <20240524193918.151fd2fc@elisabeth> Content-Language: en-US From: Danish Prakash In-Reply-To: <20240524193918.151fd2fc@elisabeth> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV using ClamSMTP Message-ID-Hash: JLZH6ZTSZGSRLB2GYBSDM5ZHEOJG4YM7 X-Message-ID-Hash: JLZH6ZTSZGSRLB2GYBSDM5ZHEOJG4YM7 X-MailFrom: contact@danishpraka.sh X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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'; Doing that after gethostname() and before sethostname() yields the desired result. I tested a few cases, seems to be fine. > >> + warn("Unable to set pasta-prefixed hostname"); >> + } >> + >> /* Wait for the parent to be ready: see main() */ >> sigemptyset(&set); >> sigaddset(&set, SIGUSR1); > -- danishpraka.sh