]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.14/tools-lib-traceevent-fix-missing-equality-check-for-.patch
autosel fixes for 4.14
[thirdparty/kernel/stable-queue.git] / queue-4.14 / tools-lib-traceevent-fix-missing-equality-check-for-.patch
1 From 6c94d959f24ae42f6c7693d4d0afb61d24496c14 Mon Sep 17 00:00:00 2001
2 From: Rikard Falkeborn <rikard.falkeborn@gmail.com>
3 Date: Tue, 9 Apr 2019 11:15:29 +0200
4 Subject: tools lib traceevent: Fix missing equality check for strcmp
5
6 [ Upstream commit f32c2877bcb068a718bb70094cd59ccc29d4d082 ]
7
8 There was a missing comparison with 0 when checking if type is "s64" or
9 "u64". Therefore, the body of the if-statement was entered if "type" was
10 "u64" or not "s64", which made the first strcmp() redundant since if
11 type is "u64", it's not "s64".
12
13 If type is "s64", the body of the if-statement is not entered but since
14 the remainder of the function consists of if-statements which will not
15 be entered if type is "s64", we will just return "val", which is
16 correct, albeit at the cost of a few more calls to strcmp(), i.e., it
17 will behave just as if the if-statement was entered.
18
19 If type is neither "s64" or "u64", the body of the if-statement will be
20 entered incorrectly and "val" returned. This means that any type that is
21 checked after "s64" and "u64" is handled the same way as "s64" and
22 "u64", i.e., the limiting of "val" to fit in for example "s8" is never
23 reached.
24
25 This was introduced in the kernel tree when the sources were copied from
26 trace-cmd in commit f7d82350e597 ("tools/events: Add files to create
27 libtraceevent.a"), and in the trace-cmd repo in 1cdbae6035cei
28 ("Implement typecasting in parser") when the function was introduced,
29 i.e., it has always behaved the wrong way.
30
31 Detected by cppcheck.
32
33 Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
34 Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
35 Cc: Tzvetomir Stoyanov <tstoyanov@vmware.com>
36 Fixes: f7d82350e597 ("tools/events: Add files to create libtraceevent.a")
37 Link: http://lkml.kernel.org/r/20190409091529.2686-1-rikard.falkeborn@gmail.com
38 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
39 Signed-off-by: Sasha Levin <sashal@kernel.org>
40 ---
41 tools/lib/traceevent/event-parse.c | 2 +-
42 1 file changed, 1 insertion(+), 1 deletion(-)
43
44 diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
45 index 3955ba9e6fcb5..7989dd6289e7a 100644
46 --- a/tools/lib/traceevent/event-parse.c
47 +++ b/tools/lib/traceevent/event-parse.c
48 @@ -2206,7 +2206,7 @@ eval_type_str(unsigned long long val, const char *type, int pointer)
49 return val & 0xffffffff;
50
51 if (strcmp(type, "u64") == 0 ||
52 - strcmp(type, "s64"))
53 + strcmp(type, "s64") == 0)
54 return val;
55
56 if (strcmp(type, "s8") == 0)
57 --
58 2.20.1
59