summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Hemminger <stephen@networkplumber.org>2023-05-08 19:12:23 -0700
committerStephen Hemminger <stephen@networkplumber.org>2023-05-13 19:02:41 -0700
commitc73a41054638ceb2b656485f768b9ec602261174 (patch)
tree28a9afc1e8e7f979e67312864ed0478c06ae977c
parentfa44c2d6f1dab40ad615bcb16fdbdb189d617ed6 (diff)
downloadiproute2-c73a41054638ceb2b656485f768b9ec602261174.tar.gz
tc_filter: fix unitialized warning
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>
-rw-r--r--tc/tc_filter.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/tc/tc_filter.c b/tc/tc_filter.c
index 12a21433..d28b1859 100644
--- a/tc/tc_filter.c
+++ b/tc/tc_filter.c
@@ -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 = {