From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 0ECA35A004E for ; Thu, 27 Jun 2024 12:11:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1719483086; bh=3ionoX5tjnOyqO6AYEKN9H8qpVWErUvZvGs34OEO6bM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Hd5CWuBN6tk4jLbYGpJ6l9qqkQVPpNZUg8K9keR19Mh86gYQpuXdO1WVIwl6wbEiE 93KUtA2DlPjygVWemhre84AXOO8RkhEmLyq1PBwg/5GiKNBPMuDnBVDq4O88x7UC8H lQbIBbVFs50Ppu0bvj7f6XtByHWm0EkNZSvk6FBHsArHiZU/Nvbs6T9TcQtWcFIbv2 9E7DI4JmDS1L/nHOAzTOBKe8cFOs2GogkcWROzJi+idxioFRbFkOqo8esyvZSAXnvU mv60mWlXlEK+uKEcp8jwmeyRiW/fT+JTZ9n/jEO72kDqV5lxMYoFtIJTP7XGamxwNy DkanMNamCx70Q== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4W8vVQ6BWcz4w2Q; Thu, 27 Jun 2024 20:11:26 +1000 (AEST) Date: Thu, 27 Jun 2024 20:11:14 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 1/4] conf: Copy up to MAXDNSRCH - 1 bytes, not MAXDNSRCH Message-ID: References: <20240626234536.3306466-1-sbrivio@redhat.com> <20240626234536.3306466-2-sbrivio@redhat.com> <20240627092653.372a58ea@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="f/RPOzfQVSa+g2+o" Content-Disposition: inline In-Reply-To: <20240627092653.372a58ea@elisabeth> Message-ID-Hash: CS42KY4QW7VFVJOVCZALSMOQ52GN3Z6B X-Message-ID-Hash: CS42KY4QW7VFVJOVCZALSMOQ52GN3Z6B X-MailFrom: dgibson@gandalf.ozlabs.org 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, Matej Hrica 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: --f/RPOzfQVSa+g2+o Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jun 27, 2024 at 09:27:01AM +0200, Stefano Brivio wrote: > On Thu, 27 Jun 2024 10:45:28 +1000 > David Gibson wrote: >=20 > > On Thu, Jun 27, 2024 at 01:45:33AM +0200, Stefano Brivio wrote: > > > Spotted by Coverity just recently. Not that it really matters as > > > MAXDNSRCH always appears to be defined as 1025, while a full domain > > > name can have up to 253 characters: it would be a bit pointless to > > > have a longer search domain. > > >=20 > > > Signed-off-by: Stefano Brivio =20 > >=20 > > Hm. So, IIRC strncpy() won't \0 terminate in the case where it > > truncates. I guess we'll get away with that here since we expect > > c->dns_search to be filled with \0 before hand. That's... more > > fragile than ideal, though. >=20 > Well, we know we start from a zero-initialised area, that's by design, > it's not that we get away with it. Without that consideration not many > things would work in this function. That's a fair point. Reviewed-by: David Gibson > Are you suggesting to use snprintf()? It looks a bit pedantic to me but > I'm fine with it. Otherwise, feel free to post a patch fixing it in a > way you feel it's ideal... >=20 > > > --- > > > conf.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > >=20 > > > diff --git a/conf.c b/conf.c > > > index e1f5422..9e47e9a 100644 > > > --- a/conf.c > > > +++ b/conf.c > > > @@ -453,7 +453,7 @@ static void get_dns(struct ctx *c) > > > while (s - c->dns_search < ARRAY_SIZE(c->dns_search) - 1 > > > /* cppcheck-suppress strtokCalled */ > > > && (p =3D strtok(NULL, " \t"))) { > > > - strncpy(s->n, p, sizeof(c->dns_search[0])); > > > + strncpy(s->n, p, sizeof(c->dns_search[0]) - 1); > > > s++; > > > *s->n =3D 0; > > > } =20 > >=20 >=20 --=20 David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson --f/RPOzfQVSa+g2+o Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmZ9Oq4ACgkQzQJF27ox 2Gdlfg/+KzLtg4ZNnnXkZwxIv/AkgHSgSlh5nq5IN2PBZixiaJ/Kn311jjXq/pyW SZQXycnbBjCPJ4ERrJKdVlbVmN+XsMsRKZQKWHwbj+CZNGojXmZ0dNSU801Yku5b 6Lx/OMRixH+02qsWSRym+CIUaSWT0oZd9satRKRkGjTUAIt6l6UU2TIxiUqc/xZt /IkkzlWargTAVmJvz91+MGgHPSduhmEmKzMorm3NfF67oHQSfG46AqNsSxy/WWqY 5Bbn3We9yeJQMqp8zSOe95cqeMfAoxDP8TFZU54fkAoumGMWqNRyQFtT9I/mTaec XV+PThfimN/iTM129G1DQT5WT6pcvPBb4Wp+vgbidhebdGQ0aqH2O/uiHvDxcpqD KxZfY5Kx/MInFbTU9Z9ryQmFVNkNMJqRhznwjW5ETFkrUTyA7+dfLPGTxmPZLtK1 6V9ByyvfROShHMtk3LmYYnt+7vNA69hRiS4gyNqvs7hEUb3XmMzhsKHRoaewj/pT tJ/eLJLetYUWfwKxVF2Hsbh0U2le9Dt+O1DcP6zWLPg2ZIeENoRraGI5qvn95RXO bFTLS/zRp3FfXYukfI1Cu7LDbeThAzTzyPpDGgNo+g2rYk/pe36YFFHx1qym6MuH 4ml6xCV65fBTeQxITbWgc9r7EM9xtvNkyBuqCflFK0EVxywNXIs= =qtb3 -----END PGP SIGNATURE----- --f/RPOzfQVSa+g2+o--