port_fwd: Don't try to read bound ports from invalid file handles
This is a minimal fix for what would be reported by Coverity as "Improper use of negative value" (CWE-394): port_fwd_init() doesn't guarantee that all the pre-opened file handles are actually valid. We should probably warn on failing open() and open_in_ns() in port_fwd_init(), too, but that's outside the scope of this minimal fix. Before commit5a0485425b
("port_fwd: Pre-open /proc/net/* files rather than on-demand"), we used to have a single open() call and a check after it. Fixes:5a0485425b
("port_fwd: Pre-open /proc/net/* files rather than on-demand") Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
b944622969
commit
9494a51a4e
1 changed files with 3 additions and 0 deletions
|
@ -45,6 +45,9 @@ static void procfs_scan_listen(int fd, unsigned int lstate,
|
||||||
unsigned int state;
|
unsigned int state;
|
||||||
char *line;
|
char *line;
|
||||||
|
|
||||||
|
if (fd < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
if (lseek(fd, 0, SEEK_SET)) {
|
if (lseek(fd, 0, SEEK_SET)) {
|
||||||
warn("lseek() failed on /proc/net file: %s", strerror(errno));
|
warn("lseek() failed on /proc/net file: %s", strerror(errno));
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue