naccyde / rpms / iproute

Forked from rpms/iproute 9 months ago
Clone

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

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