]> git.proxmox.com Git - mirror_iproute2.git/commit - lib/bpf.c
lib/bpf: Fix bytecode-file parsing
authorPhil Sutter <phil@nwl.cc>
Tue, 29 Aug 2017 15:09:45 +0000 (17:09 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Mon, 4 Sep 2017 19:06:50 +0000 (12:06 -0700)
commit7c87c7fed18d1162e045c8331cb68fa440bc5728
treeee9f7f9fd7a0c0a0a65d12e7b916e93dbbf408e5
parent460c03f3f3cc436ff4673d75722ba68a6ec9343d
lib/bpf: Fix bytecode-file parsing

The signedness of char type is implementation dependent, and there are
architectures on which it is unsigned by default. In that case, the
check whether fgetc() returned EOF failed because the return value was
assigned an (unsigned) char variable prior to comparison with EOF (which
is defined to -1). Fix this by using int as type for 'c' variable, which
also matches the declaration of fgetc().

While being at it, fix the parser logic to correctly handle multiple
empty lines and consecutive whitespace and tab characters to further
improve the parser's robustness. Note that this will still detect double
separator characters, so doesn't soften up the parser too much.

Fixes: 3da3ebfca85b8 ("bpf: Make bytecode-file reading a little more robust")
Cc: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
lib/bpf.c