From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Gibson To: passt-dev@passt.top Subject: Re: [PATCH 7/8] util: Check return value of lseek() while reading bound ports from procfs Date: Fri, 07 Oct 2022 17:58:25 +1100 Message-ID: In-Reply-To: <20221007004742.1188933-8-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0484032049204745778==" --===============0484032049204745778== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Fri, Oct 07, 2022 at 02:47:41AM +0200, Stefano Brivio wrote: > Coverity now noticed we're checking most lseek() return values, but > not this. Not really relevant, but it doesn't hurt to check we can > actually seek before reading lines. >=20 > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson > --- > util.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) >=20 > diff --git a/util.c b/util.c > index b366167..5b1e08a 100644 > --- a/util.c > +++ b/util.c > @@ -311,10 +311,14 @@ void procfs_scan_listen(struct ctx *c, uint8_t proto,= int ip_version, int ns, > path =3D "/proc/net/udp6"; > } > =20 > - if (*fd !=3D -1) > - lseek(*fd, 0, SEEK_SET); > - else if ((*fd =3D open(path, O_RDONLY | O_CLOEXEC)) < 0) > + if (*fd !=3D -1) { > + if (lseek(*fd, 0, SEEK_SET)) { > + warn("lseek() failed on %s: %s", path, strerror(errno)); > + return; > + } > + } else if ((*fd =3D open(path, O_RDONLY | O_CLOEXEC)) < 0) { > return; > + } > =20 > lineread_init(&lr, *fd); > lineread_get(&lr, &line); /* throw away header */ --=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 --===============0484032049204745778== Content-Type: application/pgp-signature Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="signature.asc" MIME-Version: 1.0 LS0tLS1CRUdJTiBQR1AgU0lHTkFUVVJFLS0tLS0KCmlRSXpCQUVCQ0FBZEZpRUVvVUx4V3U0L1dz MGRCK1h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