Skip to content

Commit eb709b5

Browse files
johnhubbardkuba-moo
authored andcommitted
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: John Hubbard <jhubbard@nvidia.com> Reviewed-by: Willem de Bruijn <willemb@google.com> Acked-by: Mat Martineau <martineau@kernel.org> Link: https://lore.kernel.org/r/20240506190204.28497-1-jhubbard@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 0d5044b commit eb709b5

3 files changed

Lines changed: 5 additions & 2 deletions

File tree

tools/testing/selftests/net/gro.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ static void setup_sock_filter(int fd)
119119
next_off = offsetof(struct ipv6hdr, nexthdr);
120120
ipproto_off = ETH_HLEN + next_off;
121121

122+
/* Overridden later if exthdrs are used: */
123+
opt_ipproto_off = ipproto_off;
124+
122125
if (strcmp(testname, "ip") == 0) {
123126
if (proto == PF_INET)
124127
optlen = sizeof(struct ip_timestamp);

tools/testing/selftests/net/ip_local_port_range.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ TEST_F(ip_local_port_range, late_bind)
359359
struct sockaddr_in v4;
360360
struct sockaddr_in6 v6;
361361
} addr;
362-
socklen_t addr_len;
362+
socklen_t addr_len = 0;
363363
const int one = 1;
364364
int fd, err;
365365
__u32 range;

tools/testing/selftests/net/mptcp/pm_nl_ctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ int add_listener(int argc, char *argv[])
12761276
struct sockaddr_storage addr;
12771277
struct sockaddr_in6 *a6;
12781278
struct sockaddr_in *a4;
1279-
u_int16_t family;
1279+
u_int16_t family = AF_UNSPEC;
12801280
int enable = 1;
12811281
int sock;
12821282
int err;

0 commit comments

Comments
 (0)