naccyde / rpms / iproute

Forked from rpms/iproute 9 months ago
Clone

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

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