diff options
author | Stefano Brivio <sbrivio@redhat.com> | 2022-10-07 02:07:33 +0200 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2022-10-15 02:10:36 +0200 |
commit | 9de65dd3f43a0ee976cc01250641834d99bbfa74 (patch) | |
tree | 735725ffcea986d72190dcaeb82618a7c578f062 /util.c | |
parent | e23024ccfff661ad5aee7c122a1833a103fbb971 (diff) | |
download | passt-9de65dd3f43a0ee976cc01250641834d99bbfa74.tar passt-9de65dd3f43a0ee976cc01250641834d99bbfa74.tar.gz passt-9de65dd3f43a0ee976cc01250641834d99bbfa74.tar.bz2 passt-9de65dd3f43a0ee976cc01250641834d99bbfa74.tar.lz passt-9de65dd3f43a0ee976cc01250641834d99bbfa74.tar.xz passt-9de65dd3f43a0ee976cc01250641834d99bbfa74.tar.zst passt-9de65dd3f43a0ee976cc01250641834d99bbfa74.zip |
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>
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -311,10 +311,14 @@ void procfs_scan_listen(struct ctx *c, uint8_t proto, int ip_version, int ns, path = "/proc/net/udp6"; } - if (*fd != -1) - lseek(*fd, 0, SEEK_SET); - else if ((*fd = open(path, O_RDONLY | O_CLOEXEC)) < 0) + if (*fd != -1) { + if (lseek(*fd, 0, SEEK_SET)) { + warn("lseek() failed on %s: %s", path, strerror(errno)); + return; + } + } else if ((*fd = open(path, O_RDONLY | O_CLOEXEC)) < 0) { return; + } lineread_init(&lr, *fd); lineread_get(&lr, &line); /* throw away header */ |