util: Check return value of lseek() while reading bound ports from procfs

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 <sbrivio@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
Stefano Brivio 2022-10-07 02:07:33 +02:00
parent e23024ccff
commit 9de65dd3f4

10
util.c
View file

@ -311,10 +311,14 @@ void procfs_scan_listen(struct ctx *c, uint8_t proto, int ip_version, int ns,
path = "/proc/net/udp6"; path = "/proc/net/udp6";
} }
if (*fd != -1) if (*fd != -1) {
lseek(*fd, 0, SEEK_SET); if (lseek(*fd, 0, SEEK_SET)) {
else if ((*fd = open(path, O_RDONLY | O_CLOEXEC)) < 0) warn("lseek() failed on %s: %s", path, strerror(errno));
return; return;
}
} else if ((*fd = open(path, O_RDONLY | O_CLOEXEC)) < 0) {
return;
}
lineread_init(&lr, *fd); lineread_init(&lr, *fd);
lineread_get(&lr, &line); /* throw away header */ lineread_get(&lr, &line); /* throw away header */