[PATCH] tools: bpftool: close va_list 'ap' by va_end()

Subsystems: bpf [general] (safe dynamic programs and tools), bpf [tooling] (bpftool), the rest

STALE1886d

2 messages, 2 authors, 2021-07-05 · open the first message on its own page

[PATCH] tools: bpftool: close va_list 'ap' by va_end()

From: gushengxian <hidden>
Date: 2021-07-01 12:00:39

From: gushengxian <redacted>

va_list 'ap' was opened but not closed by va_end(). It should be
closed by va_end() before return.

Signed-off-by: gushengxian <redacted>
---
 tools/bpf/bpftool/jit_disasm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tools/bpf/bpftool/jit_disasm.c b/tools/bpf/bpftool/jit_disasm.c
index e7e7eee9f172..3c85fd1f00cb 100644
--- a/tools/bpf/bpftool/jit_disasm.c
+++ b/tools/bpf/bpftool/jit_disasm.c
@@ -45,8 +45,10 @@ static int fprintf_json(void *out, const char *fmt, ...)
 	char *s;
 
 	va_start(ap, fmt);
-	if (vasprintf(&s, fmt, ap) < 0)
+	if (vasprintf(&s, fmt, ap) < 0) {
+		va_end(ap);
 		return -1;
+	}
 	va_end(ap);
 
 	if (!oper_count) {
-- 
2.25.1

Re: [PATCH] tools: bpftool: close va_list 'ap' by va_end()

From: Daniel Borkmann <daniel@iogearbox.net>
Date: 2021-07-05 20:58:58

On 7/1/21 2:00 PM, gushengxian wrote:
From: gushengxian <redacted>

va_list 'ap' was opened but not closed by va_end(). It should be
closed by va_end() before return.

Signed-off-by: gushengxian <redacted>
nit: 'From:' and 'SoB:' should be in standardized form, I presume in your case
this would be:

Gu Shengxian [off-list ref]
quoted hunk
---
  tools/bpf/bpftool/jit_disasm.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tools/bpf/bpftool/jit_disasm.c b/tools/bpf/bpftool/jit_disasm.c
index e7e7eee9f172..3c85fd1f00cb 100644
--- a/tools/bpf/bpftool/jit_disasm.c
+++ b/tools/bpf/bpftool/jit_disasm.c
@@ -45,8 +45,10 @@ static int fprintf_json(void *out, const char *fmt, ...)
  	char *s;
  
  	va_start(ap, fmt);
-	if (vasprintf(&s, fmt, ap) < 0)
+	if (vasprintf(&s, fmt, ap) < 0) {
+		va_end(ap);
  		return -1;
+	}
  	va_end(ap);
Small nit, please change into something like:

         va_list ap;
         char *s;
+       int err;

         va_start(ap, fmt);
-       if (vasprintf(&s, fmt, ap) < 0)
-               return -1;
+       err = vasprintf(&s, fmt, ap);
         va_end(ap);
+       if (err < 0)
+               return -1;

         if (!oper_count) {
                 int i;

Fwiw, man page says: "On some systems, va_end contains a closing '}' matching a '{' in
va_start, so that both macros must occur in the same function, and in a way that allows
this.".

Thanks,
Daniel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help