Skip to content

Commit 1fa67f8

Browse files
committed
Merge branch 'fix/wifi_netif_null_deref' into 'master'
esp_wifi: Add null pointer checks to WiFi-netif APIs Closes IDFGH-7092 See merge request espressif/esp-idf!33946
2 parents ffdf59a + 5bb10bc commit 1fa67f8

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

components/esp_netif/test_apps/test_app_esp_netif/main/esp_netif_test_lwip.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,17 @@ TEST(esp_netif, dhcp_server_state_transitions_mesh)
315315
#endif // CONFIG_ESP_WIFI_ENABLED && CONFIG_ESP_WIFI_SOFTAP_SUPPORT
316316

317317
#ifdef CONFIG_ESP_WIFI_ENABLED
318+
/*
319+
* This checks some semi-public API for null dereference
320+
*/
321+
TEST(esp_netif, wifi_netif_api_null_deref)
322+
{
323+
esp_wifi_destroy_if_driver(NULL); // returns void: just checking if won't crash
324+
TEST_ASSERT_NOT_EQUAL(ESP_OK, esp_wifi_get_if_mac(NULL, NULL));
325+
TEST_ASSERT_NOT_EQUAL(true, esp_wifi_is_if_ready_when_started(NULL));
326+
TEST_ASSERT_NOT_EQUAL(ESP_OK, esp_wifi_register_if_rxcb(NULL, NULL, NULL));
327+
}
328+
318329
/*
319330
* This test validates convenience API esp_netif_create_wifi() which creates WiFi station
320331
* or API with the specified inherent network config.
@@ -582,6 +593,7 @@ TEST_GROUP_RUNNER(esp_netif)
582593
RUN_TEST_CASE(esp_netif, create_delete_multiple_netifs)
583594
RUN_TEST_CASE(esp_netif, find_netifs)
584595
#ifdef CONFIG_ESP_WIFI_ENABLED
596+
RUN_TEST_CASE(esp_netif, wifi_netif_api_null_deref)
585597
RUN_TEST_CASE(esp_netif, create_custom_wifi_interfaces)
586598
RUN_TEST_CASE(esp_netif, create_destroy_default_wifi)
587599
#endif

components/esp_wifi/src/wifi_netif.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ wifi_netif_driver_t esp_wifi_create_if_driver(wifi_interface_t wifi_if)
114114

115115
esp_err_t esp_wifi_get_if_mac(wifi_netif_driver_t ifx, uint8_t mac[6])
116116
{
117+
if (ifx == NULL || mac == NULL) {
118+
return ESP_ERR_INVALID_ARG;
119+
}
117120
wifi_interface_t wifi_interface = ifx->wifi_if;
118121

119122
return esp_wifi_get_mac(wifi_interface, mac);
@@ -123,14 +126,17 @@ bool esp_wifi_is_if_ready_when_started(wifi_netif_driver_t ifx)
123126
{
124127
#ifdef CONFIG_ESP_WIFI_SOFTAP_SUPPORT
125128
// WiFi rxcb to be register wifi rxcb on start for AP only, station gets it registered on connect event
126-
return (ifx->wifi_if == WIFI_IF_AP);
129+
return (ifx && ifx->wifi_if == WIFI_IF_AP);
127130
#else
128131
return false;
129132
#endif
130133
}
131134

132135
esp_err_t esp_wifi_register_if_rxcb(wifi_netif_driver_t ifx, esp_netif_receive_t fn, void * arg)
133136
{
137+
if (ifx == NULL || fn == NULL || arg == NULL) {
138+
return ESP_ERR_INVALID_ARG;
139+
}
134140
if (ifx->base.netif != arg) {
135141
ESP_LOGE(TAG, "Invalid argument: supplied netif=%p does not equal to interface netif=%p", arg, ifx->base.netif);
136142
return ESP_ERR_INVALID_ARG;

0 commit comments

Comments
 (0)