Commit eb709b5f authored by John Hubbard's avatar John Hubbard Committed by Jakub Kicinski

selftests/net: fix uninitialized variables

When building with clang, via:

    make LLVM=1 -C tools/testing/selftest

...clang warns about three variables that are not initialized in all
cases:

1) The opt_ipproto_off variable is used uninitialized if "testname" is
not "ip". Willem de Bruijn pointed out that this is an actual bug, and
suggested the fix that I'm using here (thanks!).

2) The addr_len is used uninitialized, but only in the assert case,
   which bails out, so this is harmless.

3) The family variable in add_listener() is only used uninitialized in
   the error case (neither IPv4 nor IPv6 is specified), so it's also
   harmless.

Fix by initializing each variable.
Signed-off-by: default avatarJohn Hubbard <jhubbard@nvidia.com>
Reviewed-by: default avatarWillem de Bruijn <willemb@google.com>
Acked-by: default avatarMat Martineau <martineau@kernel.org>
Link: https://lore.kernel.org/r/20240506190204.28497-1-jhubbard@nvidia.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 0d5044b4
...@@ -119,6 +119,9 @@ static void setup_sock_filter(int fd) ...@@ -119,6 +119,9 @@ static void setup_sock_filter(int fd)
next_off = offsetof(struct ipv6hdr, nexthdr); next_off = offsetof(struct ipv6hdr, nexthdr);
ipproto_off = ETH_HLEN + next_off; ipproto_off = ETH_HLEN + next_off;
/* Overridden later if exthdrs are used: */
opt_ipproto_off = ipproto_off;
if (strcmp(testname, "ip") == 0) { if (strcmp(testname, "ip") == 0) {
if (proto == PF_INET) if (proto == PF_INET)
optlen = sizeof(struct ip_timestamp); optlen = sizeof(struct ip_timestamp);
......
...@@ -359,7 +359,7 @@ TEST_F(ip_local_port_range, late_bind) ...@@ -359,7 +359,7 @@ TEST_F(ip_local_port_range, late_bind)
struct sockaddr_in v4; struct sockaddr_in v4;
struct sockaddr_in6 v6; struct sockaddr_in6 v6;
} addr; } addr;
socklen_t addr_len; socklen_t addr_len = 0;
const int one = 1; const int one = 1;
int fd, err; int fd, err;
__u32 range; __u32 range;
......
...@@ -1276,7 +1276,7 @@ int add_listener(int argc, char *argv[]) ...@@ -1276,7 +1276,7 @@ int add_listener(int argc, char *argv[])
struct sockaddr_storage addr; struct sockaddr_storage addr;
struct sockaddr_in6 *a6; struct sockaddr_in6 *a6;
struct sockaddr_in *a4; struct sockaddr_in *a4;
u_int16_t family; u_int16_t family = AF_UNSPEC;
int enable = 1; int enable = 1;
int sock; int sock;
int err; int err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment