Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4d74ecf6 authored by John Fastabend's avatar John Fastabend Committed by Greg Kroah-Hartman
Browse files

bpf: fix uninitialized variable in bpf tools



[ Upstream commit 815425567dea6c54494e85050631d6bdda907c5d ]

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: fd981e3c "filter: bpf_dbg: add minimal bpf debugger"
Signed-off-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 3332858e
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -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,6 +1073,9 @@ static int cmd_load(char *arg)
		bpf_reset();
		bpf_reset_breakpoints();

		if (!cont)
			ret = CMD_ERR;
		else
			ret = cmd_load_bpf(cont);
	} else if (matches(subcmd, "pcap") == 0) {
		ret = cmd_load_pcap(cont);