@@ -70,7 +70,7 @@ static int tc_filter_modify(int cmd, unsigned int flags, int argc, char **argv)
__u32 protocol = 0;
int protocol_set = 0;
__u32 block_index = 0;
- __u32 chain_index;
+ __u32 chain_index = 0;
int chain_index_set = 0;
char *fhandle = NULL;
char d[IFNAMSIZ] = {};
@@ -594,7 +594,6 @@ static int tc_filter_list(int cmd, int argc, char **argv)
char d[IFNAMSIZ] = {};
__u32 prio = 0;
__u32 protocol = 0;
- __u32 chain_index;
__u32 block_index = 0;
char *fhandle = NULL;
@@ -676,6 +675,8 @@ static int tc_filter_list(int cmd, int argc, char **argv)
protocol = res;
filter_protocol = protocol;
} else if (matches(*argv, "chain") == 0) {
+ __u32 chain_index;
+
NEXT_ARG();
if (filter_chain_index_set)
duparg("chain", *argv);
@@ -715,7 +716,7 @@ static int tc_filter_list(int cmd, int argc, char **argv)
}
if (filter_chain_index_set)
- addattr32(&req.n, sizeof(req), TCA_CHAIN, chain_index);
+ addattr32(&req.n, sizeof(req), TCA_CHAIN, filter_chain_index);
if (brief) {
struct nla_bitfield32 flags = {
When run with -fanalyzer. tc_filter.c: In function ‘tc_filter_list’: tc_filter.c:718:17: warning: use of uninitialized value ‘chain_index’ [CWE-457] [-Wanalyzer-use-of-uninitialized-value] 718 | addattr32(&req.n, sizeof(req), TCA_CHAIN, chain_index); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ‘do_chain’: events 1-4 | | 772 | int do_chain(int argc, char **argv) | | ^~~~~~~~ | | | | | (1) entry to ‘do_chain’ | 773 | { | 774 | if (argc < 1) | | ~ | | | | | (2) following ‘true’ branch (when ‘argc <= 0’)... | 775 | return tc_filter_list(RTM_GETCHAIN, 0, NULL); | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (3) ...to here | | (4) calling ‘tc_filter_list’ from ‘do_chain’ | +--> ‘tc_filter_list’: events 5-8 | | 582 | static int tc_filter_list(int cmd, int argc, char **argv) | | ^~~~~~~~~~~~~~ | | | | | (5) entry to ‘tc_filter_list’ |...... | 597 | __u32 chain_index; | | ~~~~~~~~~~~ | | | | | (6) region created on stack here | | (7) capacity: 4 bytes |...... | 601 | while (argc > 0) { | | ~~~~~~~~ | | | | | (8) following ‘false’ branch (when ‘argc <= 0’)... | ‘tc_filter_list’: event 9 | |../include/uapi/linux/pkt_sched.h:72:35: | 72 | #define TC_H_MAKE(maj,min) (((maj)&TC_H_MAJ_MASK)|((min)&TC_H_MIN_MASK)) | | ~~~~~~^~~~~~~~~~~~~~~ | | | | | (9) ...to here tc_filter.c:698:26: note: in expansion of macro ‘TC_H_MAKE’ | 698 | req.t.tcm_info = TC_H_MAKE(prio<<16, protocol); | | ^~~~~~~~~ | ‘tc_filter_list’: events 10-16 | | 702 | if (d[0]) { | | ^ | | | | | (10) following ‘false’ branch... |...... | 707 | } else if (block_index) { | | ~~~~~~~~~~~~ | | || | | |(11) ...to here | | (12) following ‘false’ branch... |...... | 717 | if (filter_chain_index_set) | | ~~~~~~~~~~~~~~~~~~~~~~~ | | || | | |(13) ...to here | | (14) following ‘true’ branch... | 718 | addattr32(&req.n, sizeof(req), TCA_CHAIN, chain_index); | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (15) ...to here | | (16) use of uninitialized value ‘chain_index’ here | tc_filter.c:718:17: warning: use of uninitialized value ‘chain_index’ [CWE-457] [-Wanalyzer-use-of-uninitialized-value] 718 | addattr32(&req.n, sizeof(req), TCA_CHAIN, chain_index); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ‘do_filter’: events 1-4 | | 744 | int do_filter(int argc, char **argv) | | ^~~~~~~~~ | | | | | (1) entry to ‘do_filter’ | 745 | { | 746 | if (argc < 1) | | ~ | | | | | (2) following ‘true’ branch (when ‘argc <= 0’)... | 747 | return tc_filter_list(RTM_GETTFILTER, 0, NULL); | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (3) ...to here | | (4) calling ‘tc_filter_list’ from ‘do_filter’ | +--> ‘tc_filter_list’: events 5-8 | | 582 | static int tc_filter_list(int cmd, int argc, char **argv) | | ^~~~~~~~~~~~~~ | | | | | (5) entry to ‘tc_filter_list’ |...... | 597 | __u32 chain_index; | | ~~~~~~~~~~~ | | | | | (6) region created on stack here | | (7) capacity: 4 bytes |...... | 601 | while (argc > 0) { | | ~~~~~~~~ | | | | | (8) following ‘false’ branch (when ‘argc <= 0’)... | ‘tc_filter_list’: event 9 | |../include/uapi/linux/pkt_sched.h:72:35: | 72 | #define TC_H_MAKE(maj,min) (((maj)&TC_H_MAJ_MASK)|((min)&TC_H_MIN_MASK)) | | ~~~~~~^~~~~~~~~~~~~~~ | | | | | (9) ...to here tc_filter.c:698:26: note: in expansion of macro ‘TC_H_MAKE’ | 698 | req.t.tcm_info = TC_H_MAKE(prio<<16, protocol); | | ^~~~~~~~~ | ‘tc_filter_list’: events 10-16 | | 702 | if (d[0]) { | | ^ | | | | | (10) following ‘false’ branch... |...... | 707 | } else if (block_index) { | | ~~~~~~~~~~~~ | | || | | |(11) ...to here | | (12) following ‘false’ branch... |...... | 717 | if (filter_chain_index_set) | | ~~~~~~~~~~~~~~~~~~~~~~~ | | || | | |(13) ...to here | | (14) following ‘true’ branch... | 718 | addattr32(&req.n, sizeof(req), TCA_CHAIN, chain_index); | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (15) ...to here | | (16) use of uninitialized value ‘chain_index’ here | Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> --- tc/tc_filter.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)