lib/bpf: Don't leak fp in bpf_find_mntpt()

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>
This commit is contained in:
Phil Sutter 2017-08-21 16:46:51 +02:00 committed by Stephen Hemminger
parent 6e33f7b0f6
commit c3724e4bc3
1 changed files with 4 additions and 1 deletions

View File

@ -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",