]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
lib/bpf: Don't leak fp in bpf_find_mntpt()
authorPhil Sutter <phil@nwl.cc>
Mon, 21 Aug 2017 14:46:51 +0000 (16:46 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Tue, 22 Aug 2017 00:35:07 +0000 (17:35 -0700)
If fopen() succeeded but len != PATH_MAX, the function leaks the open
FILE pointer. Fix this by checking len value before calling fopen().

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
lib/bpf.c

index 4f52ad4a8f0233f11f75fff61f22463529b05a05..1dcb261dc915ff9d7446a5e0385a2648b0545e8c 100644 (file)
--- a/lib/bpf.c
+++ b/lib/bpf.c
@@ -537,8 +537,11 @@ static const char *bpf_find_mntpt(const char *fstype, unsigned long magic,
                }
        }
 
+       if (len != PATH_MAX)
+               return NULL;
+
        fp = fopen("/proc/mounts", "r");
-       if (fp == NULL || len != PATH_MAX)
+       if (fp == NULL)
                return NULL;
 
        while (fscanf(fp, "%*s %" textify(PATH_MAX) "s %99s %*s %*d %*d\n",