From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id C3A695A004E for ; Mon, 29 Jul 2024 19:55:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722275702; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ra6+2BYlOmzXMY2l+oUCSZ/79wI/ODaRVe7fY+nZyR8=; b=ZAXWhEiMHwEkIgv8WZ10+5/E6L8jtbLdJmoLO93i3O8JGZYsvVx/scT4MMHfxw/JMREvj4 Em0RxWvkOvVwubP9d89WoSfOa7lVwwBAP4ltEilw84X4krn4dR1NXp0Kgvry5aGBD/FTB9 PKz20eeRLSYeKp0eQVSP0dwKkAUDuFw= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-228-35lXeeIXM2qFlULb8J_flA-1; Mon, 29 Jul 2024 13:55:01 -0400 X-MC-Unique: 35lXeeIXM2qFlULb8J_flA-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-44f4e1569fcso47637411cf.2 for ; Mon, 29 Jul 2024 10:55:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722275700; x=1722880500; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ra6+2BYlOmzXMY2l+oUCSZ/79wI/ODaRVe7fY+nZyR8=; b=QB9RVc4PRGk3J8t8XTsE1ZMl8LVp2AaSVofcJTSHPrlE5QCvvnL4zpXktx8a7GplIg IfsnY/EF8OmVSvSF4/qKk6NUbEz/BZXegL9DLCEotKjBKMnJ2Oxq3OrPwWwXRPNejwx3 EBedORh1Th/TubhoB6JRxzA1NaickeFE7vKjwH4af4hiL2KLgtvtmip6R75l1LH/Zd0d VxYBwdJEe7oDe6Rwq/zEGlOnF5GvkZ5K2HUScZYeGXv7W6neNFJ+ihMqEAh6cd71EVOg ih8yfqMCCA2VGwUbQTCG00HO1PaiE04N0b9D4cDim+BwkhuqD4DqOhBDPotb02UX8004 MwEg== X-Gm-Message-State: AOJu0YxDWlGd8LYtag6+SZvSTdqE0lIPN0p60WaQD9PjHXzQ7iMRxpNq Yn633YyqEPrfkJ3XQedJiWGrcsgoJqjAKW7cpIDyx9WUHL2sJHQ5l5CHXVqSrPcfJyWn9KraFK6 mLYLppxDqJ/uUtUxIX2FBw5S2rNBrCfdKcKlzEREbcJ2/z7nrtg== X-Received: by 2002:ac8:5a47:0:b0:44f:eb38:2171 with SMTP id d75a77b69052e-45004f6e82bmr105626271cf.52.1722275700652; Mon, 29 Jul 2024 10:55:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE+vswkrtFu8caYFe+z9+vCPeSHQwocCaDAe/Hr/7IQG/k0S7USC7SAmQAeAko9cMCrYtZKfw== X-Received: by 2002:ac8:5a47:0:b0:44f:eb38:2171 with SMTP id d75a77b69052e-45004f6e82bmr105626081cf.52.1722275700243; Mon, 29 Jul 2024 10:55:00 -0700 (PDT) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-44fe8187c0fsm43259621cf.55.2024.07.29.10.54.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Jul 2024 10:54:59 -0700 (PDT) Date: Mon, 29 Jul 2024 19:54:23 +0200 From: Stefano Brivio To: Danish Prakash Subject: Re: [PATCH] pasta.c: modify hostname when detaching new namespace Message-ID: <20240729195423.40f77811@elisabeth> In-Reply-To: <65300ee2-aadf-4e72-b4e3-52909de5dbff@danishpraka.sh> References: <20240520083650.12032-1-contact@danishpraka.sh> <20240524124903.2004-1-contact@danishpraka.sh> <20240524193918.151fd2fc@elisabeth> <65300ee2-aadf-4e72-b4e3-52909de5dbff@danishpraka.sh> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: DQOXUWR6ME3TUOEARZZ5TPUSXLOZ3SEB X-Message-ID-Hash: DQOXUWR6ME3TUOEARZZ5TPUSXLOZ3SEB X-MailFrom: sbrivio@redhat.com 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: On Mon, 29 Jul 2024 19:26:28 +0530 Danish Prakash 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