naccyde / rpms / iproute

Forked from rpms/iproute 10 months ago
Clone

Blame SOURCES/0008-lib-bpf-Fix-bytecode-file-parsing.patch

e9acfd
From 584ca9f67952162dfdd02d984aa12640e45a4235 Mon Sep 17 00:00:00 2001
e9acfd
From: Phil Sutter <psutter@redhat.com>
e9acfd
Date: Wed, 6 Sep 2017 11:53:53 +0200
e9acfd
Subject: [PATCH] lib/bpf: Fix bytecode-file parsing
e9acfd
e9acfd
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1477491
e9acfd
Upstream Status: iproute2.git commit 7c87c7fed18d1
e9acfd
e9acfd
commit 7c87c7fed18d1162e045c8331cb68fa440bc5728
e9acfd
Author: Phil Sutter <phil@nwl.cc>
e9acfd
Date:   Tue Aug 29 17:09:45 2017 +0200
e9acfd
e9acfd
    lib/bpf: Fix bytecode-file parsing
e9acfd
e9acfd
    The signedness of char type is implementation dependent, and there are
e9acfd
    architectures on which it is unsigned by default. In that case, the
e9acfd
    check whether fgetc() returned EOF failed because the return value was
e9acfd
    assigned an (unsigned) char variable prior to comparison with EOF (which
e9acfd
    is defined to -1). Fix this by using int as type for 'c' variable, which
e9acfd
    also matches the declaration of fgetc().
e9acfd
e9acfd
    While being at it, fix the parser logic to correctly handle multiple
e9acfd
    empty lines and consecutive whitespace and tab characters to further
e9acfd
    improve the parser's robustness. Note that this will still detect double
e9acfd
    separator characters, so doesn't soften up the parser too much.
e9acfd
e9acfd
    Fixes: 3da3ebfca85b8 ("bpf: Make bytecode-file reading a little more robust")
e9acfd
    Cc: Daniel Borkmann <daniel@iogearbox.net>
e9acfd
    Signed-off-by: Phil Sutter <phil@nwl.cc>
e9acfd
    Acked-by: Daniel Borkmann <daniel@iogearbox.net>
e9acfd
---
e9acfd
 lib/bpf.c | 7 +++++--
e9acfd
 1 file changed, 5 insertions(+), 2 deletions(-)
e9acfd
e9acfd
diff --git a/lib/bpf.c b/lib/bpf.c
e9acfd
index 73dac5c..3aabf44 100644
e9acfd
--- a/lib/bpf.c
e9acfd
+++ b/lib/bpf.c
e9acfd
@@ -160,8 +160,9 @@ static int bpf_parse_string(char *arg, bool from_file, __u16 *bpf_len,
e9acfd
 
e9acfd
 	if (from_file) {
e9acfd
 		size_t tmp_len, op_len = sizeof("65535 255 255 4294967295,");
e9acfd
-		char *tmp_string, *pos, c, c_prev = ' ';
e9acfd
+		char *tmp_string, *pos, c_prev = ' ';
e9acfd
 		FILE *fp;
e9acfd
+		int c;
e9acfd
 
e9acfd
 		tmp_len = sizeof("4096,") + BPF_MAXINSNS * op_len;
e9acfd
 		tmp_string = pos = calloc(1, tmp_len);
e9acfd
@@ -180,18 +181,20 @@ static int bpf_parse_string(char *arg, bool from_file, __u16 *bpf_len,
e9acfd
 			case '\n':
e9acfd
 				if (c_prev != ',')
e9acfd
 					*(pos++) = ',';
e9acfd
+				c_prev = ',';
e9acfd
 				break;
e9acfd
 			case ' ':
e9acfd
 			case '\t':
e9acfd
 				if (c_prev != ' ')
e9acfd
 					*(pos++) = c;
e9acfd
+				c_prev = ' ';
e9acfd
 				break;
e9acfd
 			default:
e9acfd
 				*(pos++) = c;
e9acfd
+				c_prev = c;
e9acfd
 			}
e9acfd
 			if (pos - tmp_string == tmp_len)
e9acfd
 				break;
e9acfd
-			c_prev = c;
e9acfd
 		}
e9acfd
 
e9acfd
 		if (!feof(fp)) {
e9acfd
-- 
e9acfd
1.8.3.1
e9acfd