Skip to content

Commit 30c8702

Browse files
rlubosdanieldegrasse
authored andcommitted
tests: net: iface: Fix interface context misuse
The iface test suite uses two different interface types with two different context types and iid tests mixed up the two. It attempted to create a mac address for Ethernet interface (which uses struct eth_fake_context), however the net_iface_get_mac() function only works with Dummy interface context (struct net_if_test). In result the Ethernet interface context was corrupted (mac address overwritten the promisc_mode flag). Fix this by extracting mac generation code into a common function, and use it in the Ethernet iface initialization phase instead of directly in the test. This was reported by UBSAN: tests/net/iface/src/main.c:239:34: runtime error: load of value 11, which is not a valid value for type '_Bool' Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
1 parent 31b79a9 commit 30c8702

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

tests/net/iface/src/main.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,24 @@ struct net_if_test {
7878
struct net_linkaddr ll_addr;
7979
};
8080

81-
static uint8_t *net_iface_get_mac(const struct device *dev)
81+
static void test_create_mac(uint8_t *mac_buf)
8282
{
83-
struct net_if_test *data = dev->data;
84-
85-
if (data->mac_addr[2] == 0x00) {
83+
if (mac_buf[2] == 0x00) {
8684
/* 00-00-5E-00-53-xx Documentation RFC 7042 */
87-
data->mac_addr[0] = 0x00;
88-
data->mac_addr[1] = 0x00;
89-
data->mac_addr[2] = 0x5E;
90-
data->mac_addr[3] = 0x00;
91-
data->mac_addr[4] = 0x53;
92-
data->mac_addr[5] = sys_rand8_get();
85+
mac_buf[0] = 0x00;
86+
mac_buf[1] = 0x00;
87+
mac_buf[2] = 0x5E;
88+
mac_buf[3] = 0x00;
89+
mac_buf[4] = 0x53;
90+
mac_buf[5] = sys_rand8_get();
9391
}
92+
}
9493

94+
static uint8_t *net_iface_get_mac(const struct device *dev)
95+
{
96+
struct net_if_test *data = dev->data;
97+
98+
test_create_mac(data->mac_addr);
9599
memcpy(data->ll_addr.addr, data->mac_addr, sizeof(data->mac_addr));
96100
data->ll_addr.len = 6U;
97101

@@ -207,6 +211,7 @@ static void eth_fake_iface_init(struct net_if *iface)
207211

208212
ctx->iface = iface;
209213

214+
test_create_mac(ctx->mac_address);
210215
net_if_set_link_addr(iface, ctx->mac_address,
211216
sizeof(ctx->mac_address),
212217
NET_LINK_ETHERNET);
@@ -1364,8 +1369,6 @@ static void generate_iid(struct net_if *iface,
13641369
uint8_t *mac;
13651370
int ret;
13661371

1367-
(void)net_iface_get_mac(net_if_get_device(iface));
1368-
13691372
lladdr = net_if_get_link_addr(eth_iface);
13701373
mac = lladdr->addr;
13711374

0 commit comments

Comments
 (0)