1 |
From 3b2bb085939b61aab14dd8c50d381c1fc22b56e6 Mon Sep 17 00:00:00 2001 |
2 |
From: Sanskriti Sharma <sansharm@redhat.com> |
3 |
Date: Tue, 2 Oct 2018 10:29:10 -0400 |
4 |
Subject: [PATCH 021/145] perf strbuf: Match va_{add,copy} with va_end |
5 |
|
6 |
[ Upstream commit ce49d8436cffa9b7a6a5f110879d53e89dbc6746 ] |
7 |
|
8 |
Ensure that all code paths in strbuf_addv() call va_end() on the |
9 |
ap_saved copy that was made. |
10 |
|
11 |
Fixes the following coverity complaint: |
12 |
|
13 |
Error: VARARGS (CWE-237): [#def683] |
14 |
tools/perf/util/strbuf.c:106: missing_va_end: va_end was not called |
15 |
for "ap_saved". |
16 |
|
17 |
Signed-off-by: Sanskriti Sharma <sansharm@redhat.com> |
18 |
Reviewed-by: Jiri Olsa <jolsa@kernel.org> |
19 |
Cc: Joe Lawrence <joe.lawrence@redhat.com> |
20 |
Link: http://lkml.kernel.org/r/1538490554-8161-2-git-send-email-sansharm@redhat.com |
21 |
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> |
22 |
Signed-off-by: Sasha Levin <sashal@kernel.org> |
23 |
--- |
24 |
tools/perf/util/strbuf.c | 10 ++++++++-- |
25 |
1 file changed, 8 insertions(+), 2 deletions(-) |
26 |
|
27 |
diff --git a/tools/perf/util/strbuf.c b/tools/perf/util/strbuf.c |
28 |
index 3d1cf5bf7f18..9005fbe0780e 100644 |
29 |
--- a/tools/perf/util/strbuf.c |
30 |
+++ b/tools/perf/util/strbuf.c |
31 |
@@ -98,19 +98,25 @@ static int strbuf_addv(struct strbuf *sb, const char *fmt, va_list ap) |
32 |
|
33 |
va_copy(ap_saved, ap); |
34 |
len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap); |
35 |
- if (len < 0) |
36 |
+ if (len < 0) { |
37 |
+ va_end(ap_saved); |
38 |
return len; |
39 |
+ } |
40 |
if (len > strbuf_avail(sb)) { |
41 |
ret = strbuf_grow(sb, len); |
42 |
- if (ret) |
43 |
+ if (ret) { |
44 |
+ va_end(ap_saved); |
45 |
return ret; |
46 |
+ } |
47 |
len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap_saved); |
48 |
va_end(ap_saved); |
49 |
if (len > strbuf_avail(sb)) { |
50 |
pr_debug("this should not happen, your vsnprintf is broken"); |
51 |
+ va_end(ap_saved); |
52 |
return -EINVAL; |
53 |
} |
54 |
} |
55 |
+ va_end(ap_saved); |
56 |
return strbuf_setlen(sb, sb->len + len); |
57 |
} |
58 |
|
59 |
-- |
60 |
2.19.1 |
61 |
|