4.14-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Sanskriti Sharma <[email protected]>

[ Upstream commit ce49d8436cffa9b7a6a5f110879d53e89dbc6746 ]

Ensure that all code paths in strbuf_addv() call va_end() on the
ap_saved copy that was made.

Fixes the following coverity complaint:

  Error: VARARGS (CWE-237): [#def683]
  tools/perf/util/strbuf.c:106: missing_va_end: va_end was not called
  for "ap_saved".

Signed-off-by: Sanskriti Sharma <[email protected]>
Reviewed-by: Jiri Olsa <[email protected]>
Cc: Joe Lawrence <[email protected]>
Link: 
http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
 tools/perf/util/strbuf.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

--- a/tools/perf/util/strbuf.c
+++ b/tools/perf/util/strbuf.c
@@ -98,19 +98,25 @@ static int strbuf_addv(struct strbuf *sb
 
        va_copy(ap_saved, ap);
        len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);
-       if (len < 0)
+       if (len < 0) {
+               va_end(ap_saved);
                return len;
+       }
        if (len > strbuf_avail(sb)) {
                ret = strbuf_grow(sb, len);
-               if (ret)
+               if (ret) {
+                       va_end(ap_saved);
                        return ret;
+               }
                len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, 
ap_saved);
                va_end(ap_saved);
                if (len > strbuf_avail(sb)) {
                        pr_debug("this should not happen, your vsnprintf is 
broken");
+                       va_end(ap_saved);
                        return -EINVAL;
                }
        }
+       va_end(ap_saved);
        return strbuf_setlen(sb, sb->len + len);
 }
 


Reply via email to