summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2020-06-11 12:33:41 +0200
committerDaniel Borkmann <daniel@iogearbox.net>2020-06-11 23:52:19 +0200
commit2c4779eff837f1035f6f9650d246905daadd9528 (patch)
tree590ed0b5cc99e94266f3b68b14681223f85362dd
parentaa2cad0600ed2ca6a0ab39948d4db1666b6c962b (diff)
downloadlinux-2c4779eff837f1035f6f9650d246905daadd9528.tar.gz
tools, bpftool: Exit on error in function codegen
Currently, the codegen function might fail and return an error. But its callers continue without checking its return value. Since codegen can fail only in the unlikely case of the system running out of memory or the static template being malformed, just exit(-1) directly from codegen and make it void-returning. Suggested-by: Andrii Nakryiko <andrii.nakryiko@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Andrii Nakryiko <andriin@fb.com> Link: https://lore.kernel.org/bpf/20200611103341.21532-1-tklauser@distanz.ch
-rw-r--r--tools/bpf/bpftool/gen.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
index ecbae47..7443879 100644
--- a/tools/bpf/bpftool/gen.c
+++ b/tools/bpf/bpftool/gen.c
@@ -200,7 +200,7 @@ out:
return err;
}
-static int codegen(const char *template, ...)
+static void codegen(const char *template, ...)
{
const char *src, *end;
int skip_tabs = 0, n;
@@ -211,7 +211,7 @@ static int codegen(const char *template, ...)
n = strlen(template);
s = malloc(n + 1);
if (!s)
- return -ENOMEM;
+ exit(-1);
src = template;
dst = s;
@@ -225,7 +225,7 @@ static int codegen(const char *template, ...)
p_err("unrecognized character at pos %td in template '%s'",
src - template - 1, template);
free(s);
- return -EINVAL;
+ exit(-1);
}
}
@@ -236,7 +236,7 @@ static int codegen(const char *template, ...)
p_err("not enough tabs at pos %td in template '%s'",
src - template - 1, template);
free(s);
- return -EINVAL;
+ exit(-1);
}
}
/* trim trailing whitespace */
@@ -257,7 +257,8 @@ static int codegen(const char *template, ...)
va_end(args);
free(s);
- return n;
+ if (n)
+ exit(-1);
}
static int do_skeleton(int argc, char **argv)