From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 7642D5A026C for ; Mon, 27 Feb 2023 14:29:55 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4PQLvg59wTz4xDh; Tue, 28 Feb 2023 00:29:51 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1677504591; bh=7UfGZ5cEA0rXUFFZVSRqnHJePCipX00ficJbEMSQIwY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=F+Z78EXXr8hgyq/qUEgYQDJ0UJQo/U68hlcTGLwG9TPiE/YrG+J8G/DjTaU6JM9va 90OL2GlHba4rr3pF5/42D4ThI3EV8bsm9YO1rYWYZbK8YVO+Q45Wb0znmFElT7zDXP 7rPXWVD900OwfEPOVjK/+ZT7SG8rROvs91RQe8NA= Date: Mon, 27 Feb 2023 21:50:25 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 2/3] tcp: Avoid false (but convoluted) positive Coverity CWE-476 warning Message-ID: References: <20230227095941.225672-1-sbrivio@redhat.com> <20230227095941.225672-3-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="pyVxDhDlC5LmnpH+" Content-Disposition: inline In-Reply-To: <20230227095941.225672-3-sbrivio@redhat.com> Message-ID-Hash: FMZYEGWPXXFWEVFK6PL4EQKGNLG23OPW X-Message-ID-Hash: FMZYEGWPXXFWEVFK6PL4EQKGNLG23OPW 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 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: --pyVxDhDlC5LmnpH+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Feb 27, 2023 at 10:59:40AM +0100, Stefano Brivio wrote: > If there are no TCP options in the header, tcp_tap_handler() will > pass the corresponding pointer, fetched via packet_get(), as NULL to > tcp_conn_from_sock_finish(), which in turn indirectly calls > tcp_opt_get(). >=20 > If there are no options, tcp_opt_get() will stop right away because > the option length is indicated as zero. However, if the logic is > complicated enough to follow for static checkers, adding an explicit > check against NULL in tcp_opt_get() is probably a good idea. >=20 > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson > --- > tcp.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) >=20 > diff --git a/tcp.c b/tcp.c > index 41210a3..561064e 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -1114,7 +1114,7 @@ static int tcp_opt_get(const char *opts, size_t len= , uint8_t type_find, > { > uint8_t type, optlen; > =20 > - if (!len) > + if (!opts || !len) > return -1; > =20 > for (; len >=3D 2; opts +=3D optlen, len -=3D optlen) { --=20 David Gibson | 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 --pyVxDhDlC5LmnpH+ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmP8iuoACgkQzQJF27ox 2GcESA//S6I4sgLkk2y622CyLW+iFbcT2u3UY5iAc/CgxMJaVUDZ+i1TJ+ADZawM bRrN/n5jTXT//UyCAE+c434+gOAVHlDffQ/LxeXmO3YS11yntEbLygQaDkC2fHmL krt+UXatWUrsb5m9TtyEdYnKJZmiyzQ17/+jwO5Vghao8WzdTuas3haU8OJD/4Ox 99hjwGOyO7EYyETWu0ZKU4QUGx2mRBH26MyOwFVVps1VTkYHj574xoPmDlOZsttu +SeuMTZepc4ePtYJe3dF+tIJ9zy/qAjIRTqauhIS4OAOtVSJmCGREUZ8tKmDBaJK SpQ+e9zirL/CM0KT08yC+NIYWPZESobx0JJ1BF5N5rM909LNnfV8041gNnwRpmSL yXB+UB4IrN1xidlYMuwwFgjsKI9cJfl4sFLJkuhSvqEbMneDwY78M2PXE6727nip PFvt7nI3+XSJreyd0geyRcMezmUYqkcgVRUumPpntH6olgbUV7FEVHNnafxLPHQi gRBEX0TqlqFLUUZvN/oyKaai47s0vK4Ug8vP3Mud9wEXcjfmyLSI1ePpim1xCzQq R/d9hcS1oli6Xliq138nFb1BY+ZIS0NaEAcIBF77Zwu0CFBFPlfdo1gSt1P+JwmJ AZRYcCGxrLcupgOXCl4Dqphi+Pz+7eign4geY02LA9o9u8S94lI= =Uibw -----END PGP SIGNATURE----- --pyVxDhDlC5LmnpH+--