From 466008a82144887587f4e4794a5e281a0bd9c7f6 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Wed, 13 Mar 2024 15:43:00 -0700 Subject: [PATCH] Internal change. PiperOrigin-RevId: 615567691 --- test/syscalls/linux/ip6tables.cc | 5 ++++- test/syscalls/linux/iptables.h | 3 +++ test/syscalls/linux/tuntap.cc | 7 +++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/test/syscalls/linux/ip6tables.cc b/test/syscalls/linux/ip6tables.cc index d11b45d4a..c1f80713b 100644 --- a/test/syscalls/linux/ip6tables.cc +++ b/test/syscalls/linux/ip6tables.cc @@ -15,6 +15,8 @@ #include #include +#include + #include "gtest/gtest.h" #include "test/syscalls/linux/iptables.h" #include "test/util/capability_util.h" @@ -191,7 +193,8 @@ TEST(IP6TablesTest, InitialEntries) { reinterpret_cast(entries->entrytable) + entry_offset); // ipv6 should be zeroed. - struct ip6t_ip6 zeroed = {}; + struct ip6t_ip6 zeroed; + memset(&zeroed, 0, sizeof(zeroed)); ASSERT_EQ(memcmp(static_cast(&zeroed), static_cast(&entry->ipv6), sizeof(zeroed)), 0); diff --git a/test/syscalls/linux/iptables.h b/test/syscalls/linux/iptables.h index d0fc10fea..8475802f8 100644 --- a/test/syscalls/linux/iptables.h +++ b/test/syscalls/linux/iptables.h @@ -221,6 +221,9 @@ enum SockOpts6 { // ip6t_ip6 specifies basic matching criteria that can be applied by examining // only the IP header of a packet. +// Must be POD so that it can be zero-initialized using memset() because +// initializing by "{}" leaves it partially uninitialized for paddings and +// nested unions. struct ip6t_ip6 { // Source IP address. struct in6_addr src; diff --git a/test/syscalls/linux/tuntap.cc b/test/syscalls/linux/tuntap.cc index 380d2e39e..169559ac2 100644 --- a/test/syscalls/linux/tuntap.cc +++ b/test/syscalls/linux/tuntap.cc @@ -26,6 +26,7 @@ #include #include +#include #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -220,13 +221,15 @@ TEST_F(TuntapTest, CreateFixedNameInterface) { FileDescriptor fd = ASSERT_NO_ERRNO_AND_VALUE(Open(kDevNetTun, O_RDWR)); - struct ifreq ifr_set = {}; + struct ifreq ifr_set; + memset(&ifr_set, 0, sizeof(ifr_set)); ifr_set.ifr_flags = IFF_TAP; strncpy(ifr_set.ifr_name, kTapName, IFNAMSIZ); EXPECT_THAT(ioctl(fd.get(), TUNSETIFF, &ifr_set), SyscallSucceedsWithValue(0)); - struct ifreq ifr_get = {}; + struct ifreq ifr_get; + memset(&ifr_get, 0, sizeof(ifr_get)); EXPECT_THAT(ioctl(fd.get(), TUNGETIFF, &ifr_get), SyscallSucceedsWithValue(0));