* [bpf PATCH] bpf: fix uninitialized variable in bpf tools
@ 2018-04-25 22:08 John Fastabend
2018-04-26 20:55 ` Daniel Borkmann
0 siblings, 1 reply; 2+ messages in thread
From: John Fastabend @ 2018-04-25 22:08 UTC (permalink / raw)
To: ast, daniel, jbenc; +Cc: netdev
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: fd981e3c321a "filter: bpf_dbg: add minimal bpf debugger"
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
---
tools/bpf/bpf_dbg.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/tools/bpf/bpf_dbg.c b/tools/bpf/bpf_dbg.c
index 4f254bc..61b9aa5 100644
--- a/tools/bpf/bpf_dbg.c
+++ b/tools/bpf/bpf_dbg.c
@@ -1063,7 +1063,7 @@ static int cmd_load_pcap(char *file)
static int cmd_load(char *arg)
{
- char *subcmd, *cont, *tmp = strdup(arg);
+ char *subcmd, *cont = NULL, *tmp = strdup(arg);
int ret = CMD_OK;
subcmd = strtok_r(tmp, " ", &cont);
@@ -1073,7 +1073,10 @@ static int cmd_load(char *arg)
bpf_reset();
bpf_reset_breakpoints();
- ret = cmd_load_bpf(cont);
+ if (!cont)
+ ret = CMD_ERR;
+ else
+ ret = cmd_load_bpf(cont);
} else if (matches(subcmd, "pcap") == 0) {
ret = cmd_load_pcap(cont);
} else {
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [bpf PATCH] bpf: fix uninitialized variable in bpf tools
2018-04-25 22:08 [bpf PATCH] bpf: fix uninitialized variable in bpf tools John Fastabend
@ 2018-04-26 20:55 ` Daniel Borkmann
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Borkmann @ 2018-04-26 20:55 UTC (permalink / raw)
To: John Fastabend, ast, jbenc; +Cc: netdev
On 04/26/2018 12:08 AM, John Fastabend wrote:
> 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: fd981e3c321a "filter: bpf_dbg: add minimal bpf debugger"
> Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Applied to bpf tree, thanks John!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-04-26 20:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-25 22:08 [bpf PATCH] bpf: fix uninitialized variable in bpf tools John Fastabend
2018-04-26 20:55 ` Daniel Borkmann
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.