Skip to content

Commit 8154255

Browse files
jrfastabborkmann
authored andcommitted
bpf: fix uninitialized variable in bpf tools
Here the variable cont is used as the saved_pointer for a call to strtok_r(). It is safe to use the value uninitialized in this context however and the later reference is only ever used if the strtok_r is successful. But, 'gcc-5' at least doesn't have all this knowledge so initialize cont to NULL. Additionally, do the natural NULL check before accessing just for completness. The warning is the following: ./bpf/tools/bpf/bpf_dbg.c: In function ‘cmd_load’: ./bpf/tools/bpf/bpf_dbg.c:1077:13: warning: ‘cont’ may be used uninitialized in this function [-Wmaybe-uninitialized] } else if (matches(subcmd, "pcap") == 0) { Fixes: fd981e3 "filter: bpf_dbg: add minimal bpf debugger" Signed-off-by: John Fastabend <john.fastabend@gmail.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent 25eb0ea commit 8154255

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

tools/bpf/bpf_dbg.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ static int cmd_load_pcap(char *file)
10631063

10641064
static int cmd_load(char *arg)
10651065
{
1066-
char *subcmd, *cont, *tmp = strdup(arg);
1066+
char *subcmd, *cont = NULL, *tmp = strdup(arg);
10671067
int ret = CMD_OK;
10681068

10691069
subcmd = strtok_r(tmp, " ", &cont);
@@ -1073,7 +1073,10 @@ static int cmd_load(char *arg)
10731073
bpf_reset();
10741074
bpf_reset_breakpoints();
10751075

1076-
ret = cmd_load_bpf(cont);
1076+
if (!cont)
1077+
ret = CMD_ERR;
1078+
else
1079+
ret = cmd_load_bpf(cont);
10771080
} else if (matches(subcmd, "pcap") == 0) {
10781081
ret = cmd_load_pcap(cont);
10791082
} else {

0 commit comments

Comments
 (0)