selftest:net: Fix uninit pointers and return values
Subsystems (5)
PATCH 1/1 selftest:net: Fix uninit pointers and return values
Fix uninitialized character pointers, and functions that return
undefined values. These issues were caught by running clang using LLVM=1
option; and are as follows:
--
ovpn-cli.c:1587:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
1587 | if (!sock) {
| ^~~~~ovpn-cli.c:1635:9: note: uninitialized use occurs here
1635 | return ret;
| ^~~
ovpn-cli.c:1587:2: note: remove the 'if' if its condition is always false
1587 | if (!sock) {
| ^~~~~~~~~~~~
1588 | fprintf(stderr, "cannot allocate netlink socket\n");
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1589 | goto err_free;
| ~~~~~~~~~~~~~~
1590 | }
| ~
ovpn-cli.c:1584:15: note: initialize the variable 'ret' to silence this warning
1584 | int mcid, ret;
| ^
| = 0
ovpn-cli.c:2107:7: warning: variable 'ret' is used uninitialized whenever switch case is taken [-Wsometimes-uninitialized]
2107 | case CMD_INVALID:
| ^~~~~~~~~~~ovpn-cli.c:2111:9: note: uninitialized use occurs here
2111 | return ret;
| ^~~
ovpn-cli.c:1939:12: note: initialize the variable 'ret' to silence this warning
1939 | int n, ret;
| ^
|
--
txtimestamp.c:240:2: warning: variable 'tsname' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]
240 | default:
| ^~~~~~~txtimestamp.c:244:20: note: uninitialized use occurs here
244 | __print_timestamp(tsname, &tss->ts[0], tskey, payload_len);
| ^~~~~~
txtimestamp.c:220:20: note: initialize the variable 'tsname' to silence this warning
220 | const char *tsname;
| ^
| = NULL
--
so_txtime.c:210:3: warning: variable 'reason' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]
210 | default:
| ^~~~~~~so_txtime.c:219:27: note: uninitialized use occurs here
219 | data[ret - 1], tstamp, reason);
| ^~~~~~
so_txtime.c:177:21: note: initialize the variable 'reason' to silence this warning
177 | const char *reason;
| ^
|--
---
tools/testing/selftests/net/ovpn/ovpn-cli.c +2 -2
@@ -1581,7 +1581,7 @@ static int ovpn_listen_mcast(void) {struct nl_sock *sock;struct nl_cb *cb; -int mcid, ret; +int mcid, ret =-1 ; sock =nl_socket_alloc ();if (!sock) {
@@ -1936,7 +1936,7 @@ static int ovpn_run_cmd(struct ovpn_ctx *ovpn) {char peer_id[10 ], vpnip[INET6_ADDRSTRLEN ], laddr[128 ], lport[10 ];char raddr[128 ], rport[10 ]; -int n, ret; +int n, ret =-1 ;FILE *fp;switch (ovpn->cmd) {
tools/testing/selftests/net/so_txtime.c +1 -1
@@ -174,7 +174,7 @@ static int do_recv_errqueue_timeout(int fdt) msg.msg_controllen =sizeof (control);while (1 ) { -const char *reason; +const char *reason =NULL ; ret =recvmsg (fdt, &msg,MSG_ERRQUEUE );if (ret ==-1 && errno ==EAGAIN )
tools/testing/selftests/net/txtimestamp.c +1 -1
@@ -217,7 +217,7 @@ static void print_timestamp_usr(void)static void print_timestamp (struct scm_timestamping *tss,int tstype,int tskey,int payload_len) { -const char *tsname; +const char *tsname =NULL ;validate_key (tskey, tstype);
Signature · 1 line
2.47.3
Willem de Bruijn
maintainer[PATCH net]
and a Fixes tag
Quoted 26 lines · Sidharth Seela
Fix uninitialized character pointers, and functions that return
undefined values. These issues were caught by running clang using LLVM=1
option; and are as follows:
--
ovpn-cli.c:1587:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]1587 | if (!sock) { | ^~~~~ovpn-cli.c:1635:9: note: uninitialized use occurs here
1635 | return ret;
| ^~~
ovpn-cli.c:1587:2: note: remove the 'if' if its condition is always false1587 | if (!sock) { | ^~~~~~~~~~~~ 1588 | fprintf(stderr, "cannot allocate netlink socket\n"); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1589 | goto err_free; | ~~~~~~~~~~~~~~ 1590 | } | ~ ovpn-cli.c:1584:15: note: initialize the variable 'ret' to silence this warning 1584 | int mcid, ret; | ^ | = 0 ovpn-cli.c:2107:7: warning: variable 'ret' is used uninitialized whenever switch case is taken [-Wsometimes-uninitialized] 2107 | case CMD_INVALID: | ^~~~~~~~~~~
Quoted 6 lines
ovpn-cli.c:2111:9: note: uninitialized use occurs here
2111 | return ret;
| ^~~
ovpn-cli.c:1939:12: note: initialize the variable 'ret' to silence this warning
1939 | int n, ret;
| ^
These two look legitimate.
Quoted 4 lines
|--
txtimestamp.c:240:2: warning: variable 'tsname' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]
240 | default:
Does not need a fix. The default statement calls error() which exits the program.
Quoted 5 lines
| ^~~~~~~txtimestamp.c:244:20: note: uninitialized use occurs here
244 |__print_timestamp(tsname, &tss->ts[0], tskey, payload_len);
| ^~~~~~
txtimestamp.c:220:20: note: initialize the variable 'tsname' to silence this warning
Quoted 7 lines
220 | const char *tsname;
| ^
| = NULL
--
so_txtime.c:210:3: warning: variable 'reason' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]
210 | default:
| ^~~~~~~Same.
Quoted 10 lines
so_txtime.c:219:27: note: uninitialized use occurs here
219 | data[ret - 1], tstamp, reason);
| ^~~~~~
so_txtime.c:177:21: note: initialize the variable 'reason' to silence this warning177 | const char *reason; | ^ |--
Signed-off-by Sidharth Seela <[email protected]>
Agreed on all the occurrences and the ovpn fixes.
Quoted 29 lines
---
tools/testing/selftests/net/ovpn/ovpn-cli.c +2
-2@@ -1581,7 +1581,7 @@ static int ovpn_listen_mcast(void) {struct nl_sock *sock;struct nl_cb *cb; -int mcid, ret; +int mcid, ret =-1 ; sock =nl_socket_alloc ();if (!sock) {@@ -1936,7 +1936,7 @@ static int ovpn_run_cmd(struct ovpn_ctx *ovpn) {char peer_id[10 ], vpnip[INET6_ADDRSTRLEN ], laddr[128 ], lport[10 ];char raddr[128 ], rport[10 ]; -int n, ret; +int n, ret =-1 ;FILE *fp;switch (ovpn->cmd) {tools/testing/selftests/net/so_txtime.c +0
-0
tools/testing/selftests/net/so_txtime.c static int do_recv_errqueue_timeout(int fdt) · line 177
Quoted 5 lines
tools/testing/selftests/net/so_txtime.c +1
-1@@ -174,7 +174,7 @@ static int do_recv_errqueue_timeout(int fdt) msg.msg_controllen =sizeof (control);while (1 ) { -const char *reason; +const char *reason =NULL ;
Since reason is a string that's printed, better to initialize it to a string. Preferably in the case statement, e.g., "unknown errno".
Quoted 19 lines
tools/testing/selftests/net/so_txtime.c +0
-0ret =recvmsg (fdt, &msg,MSG_ERRQUEUE );if (ret ==-1 && errno ==EAGAIN )tools/testing/selftests/net/txtimestamp.c +1
-1@@ -217,7 +217,7 @@ static void print_timestamp_usr(void)static void print_timestamp (struct scm_timestamping *tss,int tstype,int tskey,int payload_len) { -const char *tsname; +const char *tsname =NULL ;validate_key (tskey, tstype);Signature · 1 line
2.47.3
Quoted 2 lines · Willem de Bruijn
[PATCH net]
and a Fixes tag
Thankyou, I'll add that.
Quoted 2 lines
Does not need a fix. The default statement calls
error()which exits the program. Same.
Yes, you are correct.
Quoted 1 line
Agreed on all the occurrences and the ovpn fixes.
Alright, I'll send v2, with improvements and a changelog.
Signature · 3 lines
Thanks, Sidharth Seela www.realtimedesign.org