Skip to contentSkip to conversation

net: Fix uninit character pointer and return values

PATCH Superseded Sidharth Seela 2 participants 3 messages Sep 29, 2025

Subsystems (4)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: Fix uninit character pointer and return values

Fix uninitialized character pointer, 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;
      |                   ^
      |
--
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;
      |                                   ^
      |

--

Fixes 959bc330a439 ("testing/selftests: add test tool and scripts for ovpn module")

ovpn module")

Fixes ca8826095e4d4 ("selftests/net: report etf errors correctly")

v2:
- Use subsystem name "net".
- Add fixes tags.
- Remove txtimestamp fix as default case calls error.
- Assign constant error string instead of NULL.
--

tools/testing/selftests/net/ovpn/ovpn-cli.c +2 -2
index 9201f2905f2c..20d00378f34a 100644
@@ -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
index 8457b7ccbc09..5bf3c483069b 100644
@@ -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 = "unknown errno";
 
 		ret = recvmsg(fdt, &msg, MSG_ERRQUEUE);
 		if (ret == -1 && errno == EAGAIN)
Signature · 1 line
2.47.3
#1 lore raw

Reminder: use the net prefix: [PATCH net v2]

Quoted 37 lines · Sidharth Seela

Fix uninitialized character pointer, 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;
      |                   ^
      |
--
so_txtime.c:210:3: warning: variable 'reason' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]
  210 |                 default:
      |                 ^~~~~~~
Quoted 7 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 warning

  177 |                 const char *reason;
      |                                   ^
      |

My previous response accidentally left a state comment. The main feedback still held:

This default case calls error() and exits the program, so this cannot happen.

Quoted 5 lines

--

Fixes 959bc330a439 ("testing/selftests: add test tool and scripts for ovpn module")

ovpn module")

Fixes ca8826095e4d4 ("selftests/net: report etf errors correctly")
Quoted 8 lines

v2:
- Use subsystem name "net".
- Add fixes tags.
- Remove txtimestamp fix as default case calls error.
- Assign constant error string instead of NULL.
--

End the commit with the Signed-off-by block. Either move changelog above that, or below three (not two) dashes.

Quoted 38 lines
tools/testing/selftests/net/ovpn/ovpn-cli.c +2 -2
index 9201f2905f2c..20d00378f34a 100644
@@ -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
index 8457b7ccbc09..5bf3c483069b 100644
@@ -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 = "unknown errno";
 
 		ret = recvmsg(fdt, &msg, MSG_ERRQUEUE);
 		if (ret == -1 && errno == EAGAIN)
Signature · 1 line
2.47.3
#2 lore raw
Quoted 2 lines · Willem de Bruijn

Reminder: use the net prefix: [PATCH net v2]

Oh I thought you meant me to change the subsytem in the subject. Changing.

Quoted 4 lines

My previous response accidentally left a state comment. The main feedback still held:
This default case calls error() and exits the program, so this cannot happen.

Alright, I thought error() is like perror(). After checking man pages, the status being non-zero leads to exit(). So yes, it makes sense now, the switch case, either loads up a value in the 'reason' or exits().

Quoted 2 lines

End the commit with the Signed-off-by block. Either move changelog above that, or below three (not two) dashes.

Alright, Thank you for taking the time to reply. Sending w/ changes.

Signature · 3 lines
Thanks,
Sidharth Seela
www.realtimedesign.org