提交 ce081fc1 编写于 作者: S Sanskriti Sharma 提交者: Greg Kroah-Hartman

perf strbuf: Match va_{add,copy} with va_end

[ 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: NSanskriti Sharma <sansharm@redhat.com>
Reviewed-by: NJiri Olsa <jolsa@kernel.org>
Cc: Joe Lawrence <joe.lawrence@redhat.com>
Link: http://lkml.kernel.org/r/1538490554-8161-2-git-send-email-sansharm@redhat.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 9aa0d85d
...@@ -98,19 +98,25 @@ static int strbuf_addv(struct strbuf *sb, const char *fmt, va_list ap) ...@@ -98,19 +98,25 @@ static int strbuf_addv(struct strbuf *sb, const char *fmt, va_list ap)
va_copy(ap_saved, ap); va_copy(ap_saved, ap);
len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, 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; return len;
}
if (len > strbuf_avail(sb)) { if (len > strbuf_avail(sb)) {
ret = strbuf_grow(sb, len); ret = strbuf_grow(sb, len);
if (ret) if (ret) {
va_end(ap_saved);
return ret; return ret;
}
len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap_saved); len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap_saved);
va_end(ap_saved); va_end(ap_saved);
if (len > strbuf_avail(sb)) { if (len > strbuf_avail(sb)) {
pr_debug("this should not happen, your vsnprintf is broken"); pr_debug("this should not happen, your vsnprintf is broken");
va_end(ap_saved);
return -EINVAL; return -EINVAL;
} }
} }
va_end(ap_saved);
return strbuf_setlen(sb, sb->len + len); return strbuf_setlen(sb, sb->len + len);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册