From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH 7/8] util: Check return value of lseek() while reading bound ports from procfs Date: Fri, 07 Oct 2022 02:47:41 +0200 Message-ID: <20221007004742.1188933-8-sbrivio@redhat.com> In-Reply-To: <20221007004742.1188933-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============6884885806295984248==" --===============6884885806295984248== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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. Signed-off-by: Stefano Brivio --- util.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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, i= nt 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 2.35.1 --===============6884885806295984248==--