From 79ae89f74028ef9e9d97630cbdc11d7ee50b7dbc Mon Sep 17 00:00:00 2001 From: Jerome Coutant Date: Tue, 14 Sep 2021 10:46:52 +0200 Subject: [PATCH] connectivity tests: avoid crash with null pointer --- connectivity/netsocket/tests/TESTS/netsocket/dns/main.cpp | 1 + connectivity/netsocket/tests/TESTS/netsocket/tcp/main.cpp | 1 + connectivity/netsocket/tests/TESTS/netsocket/tls/main.cpp | 1 + connectivity/netsocket/tests/TESTS/netsocket/udp/main.cpp | 1 + .../tests/TESTS/network/interface/networkinterface_status.cpp | 1 + .../netsocket/tests/TESTS/network/wifi/wifi_connect.cpp | 4 ++++ .../TESTS/network/wifi/wifi_connect_disconnect_repeat.cpp | 4 ++++ .../tests/TESTS/network/wifi/wifi_connect_nocredentials.cpp | 4 ++++ .../tests/TESTS/network/wifi/wifi_connect_params_channel.cpp | 4 ++++ .../TESTS/network/wifi/wifi_connect_params_channel_fail.cpp | 4 ++++ .../tests/TESTS/network/wifi/wifi_connect_params_null.cpp | 4 ++++ .../TESTS/network/wifi/wifi_connect_params_valid_secure.cpp | 4 ++++ .../tests/TESTS/network/wifi/wifi_connect_secure.cpp | 4 ++++ .../tests/TESTS/network/wifi/wifi_connect_secure_fail.cpp | 4 ++++ .../netsocket/tests/TESTS/network/wifi/wifi_get_rssi.cpp | 4 ++++ connectivity/netsocket/tests/TESTS/network/wifi/wifi_scan.cpp | 4 ++++ .../netsocket/tests/TESTS/network/wifi/wifi_scan_null.cpp | 4 ++++ .../netsocket/tests/TESTS/network/wifi/wifi_set_channel.cpp | 4 ++++ .../tests/TESTS/network/wifi/wifi_set_credential.cpp | 4 ++++ 19 files changed, 61 insertions(+) diff --git a/connectivity/netsocket/tests/TESTS/netsocket/dns/main.cpp b/connectivity/netsocket/tests/TESTS/netsocket/dns/main.cpp index 01e35d453f1..d9723f44cb6 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/dns/main.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/dns/main.cpp @@ -168,6 +168,7 @@ static void net_bringup() MBED_ASSERT(MBED_CONF_APP_DNS_TEST_HOSTS_NUM >= MBED_CONF_NSAPI_DNS_CACHE_SIZE && MBED_CONF_APP_DNS_TEST_HOSTS_NUM >= MBED_CONF_APP_DNS_SIMULT_QUERIES + 1); net = NetworkInterface::get_default_instance(); + TEST_ASSERT_NOT_NULL_MESSAGE(net, "No NetworkInterface configured"); nsapi_error_t err = net->connect(); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err); SocketAddress address; diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tcp/main.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tcp/main.cpp index f2be5b880c4..0dde5a99d3f 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tcp/main.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tcp/main.cpp @@ -75,6 +75,7 @@ nsapi_version_t get_ip_version() static void _ifup() { NetworkInterface *net = NetworkInterface::get_default_instance(); + TEST_ASSERT_NOT_NULL_MESSAGE(net, "No NetworkInterface configured"); nsapi_error_t err = net->connect(); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err); SocketAddress address; diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tls/main.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tls/main.cpp index f6489a3d736..aa256a7128e 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tls/main.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tls/main.cpp @@ -71,6 +71,7 @@ void drop_bad_packets(TLSSocket &sock, int orig_timeout) static void _ifup() { NetworkInterface *net = NetworkInterface::get_default_instance(); + TEST_ASSERT_NOT_NULL_MESSAGE(net, "No NetworkInterface configured"); nsapi_error_t err = net->connect(); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err); SocketAddress address; diff --git a/connectivity/netsocket/tests/TESTS/netsocket/udp/main.cpp b/connectivity/netsocket/tests/TESTS/netsocket/udp/main.cpp index b3bfa899fc5..4b88b607b2a 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/udp/main.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/udp/main.cpp @@ -62,6 +62,7 @@ void drop_bad_packets(UDPSocket &sock, int orig_timeout) static void _ifup() { NetworkInterface *net = NetworkInterface::get_default_instance(); + TEST_ASSERT_NOT_NULL_MESSAGE(net, "No NetworkInterface configured"); nsapi_error_t err = net->connect(); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err); SocketAddress address; diff --git a/connectivity/netsocket/tests/TESTS/network/interface/networkinterface_status.cpp b/connectivity/netsocket/tests/TESTS/network/interface/networkinterface_status.cpp index 8ed56986668..ce95d08d6c7 100644 --- a/connectivity/netsocket/tests/TESTS/network/interface/networkinterface_status.cpp +++ b/connectivity/netsocket/tests/TESTS/network/interface/networkinterface_status.cpp @@ -75,6 +75,7 @@ void NETWORKINTERFACE_STATUS() current_status = NSAPI_STATUS_ERROR_UNSUPPORTED; net = NetworkInterface::get_default_instance(); + TEST_ASSERT_NOT_NULL_MESSAGE(net, "No NetworkInterface configured"); net->attach(status_cb); net->set_blocking(true); diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect.cpp index aec259f130b..fbd6f59c219 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect.cpp @@ -30,6 +30,10 @@ using namespace utest::v1; void wifi_connect(void) { WiFiInterface *wifi = get_interface(); + TEST_ASSERT(wifi); + if (wifi == NULL) { + return; + } char ssid[SSID_MAX_LEN + 1] = MBED_CONF_APP_WIFI_UNSECURE_SSID; diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_disconnect_repeat.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_disconnect_repeat.cpp index de24fa53130..898233da018 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_disconnect_repeat.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_disconnect_repeat.cpp @@ -28,6 +28,10 @@ using namespace utest::v1; void wifi_connect_disconnect_repeat(void) { WiFiInterface *wifi = get_interface(); + TEST_ASSERT(wifi); + if (wifi == NULL) { + return; + } nsapi_error_t error; error = wifi->set_credentials(MBED_CONF_APP_WIFI_SECURE_SSID, MBED_CONF_APP_WIFI_PASSWORD, get_security()); diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_nocredentials.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_nocredentials.cpp index 73e8c015fca..bae1a6ed9e9 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_nocredentials.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_nocredentials.cpp @@ -26,6 +26,10 @@ using namespace utest::v1; void wifi_connect_nocredentials(void) { WiFiInterface *wifi = get_interface(); + TEST_ASSERT(wifi); + if (wifi == NULL) { + return; + } nsapi_error_t error_connect, error_disconnect; error_connect = wifi->connect(); error_disconnect = wifi->disconnect(); diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_channel.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_channel.cpp index a7fb57c4c6c..6be5b7d0db9 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_channel.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_channel.cpp @@ -28,6 +28,10 @@ using namespace utest::v1; void wifi_connect_params_channel(void) { WiFiInterface *wifi = get_interface(); + TEST_ASSERT(wifi); + if (wifi == NULL) { + return; + } if (wifi->set_channel(1) == NSAPI_ERROR_UNSUPPORTED && wifi->set_channel(36) == NSAPI_ERROR_UNSUPPORTED) { TEST_IGNORE_MESSAGE("set_channel() not supported"); diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_channel_fail.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_channel_fail.cpp index 40b2bc9a0de..fc27f34dd78 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_channel_fail.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_channel_fail.cpp @@ -28,6 +28,10 @@ using namespace utest::v1; void wifi_connect_params_channel_fail(void) { WiFiInterface *wifi = get_interface(); + TEST_ASSERT(wifi); + if (wifi == NULL) { + return; + } if (wifi->set_channel(1) == NSAPI_ERROR_UNSUPPORTED && wifi->set_channel(36) == NSAPI_ERROR_UNSUPPORTED) { TEST_IGNORE_MESSAGE("set_channel() not supported"); diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_null.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_null.cpp index 0c2350dfcec..8fbe4be3ea1 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_null.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_null.cpp @@ -27,6 +27,10 @@ void wifi_connect_params_null(void) { nsapi_error_t error; WiFiInterface *wifi = get_interface(); + TEST_ASSERT(wifi); + if (wifi == NULL) { + return; + } error = wifi->connect(NULL, NULL); wifi->disconnect(); TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, error); diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_valid_secure.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_valid_secure.cpp index 2b3f1e9ec88..3264d90c5cd 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_valid_secure.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_valid_secure.cpp @@ -28,6 +28,10 @@ using namespace utest::v1; void wifi_connect_params_valid_secure(void) { WiFiInterface *wifi = get_interface(); + TEST_ASSERT(wifi); + if (wifi == NULL) { + return; + } if (wifi->connect(MBED_CONF_APP_WIFI_SECURE_SSID, MBED_CONF_APP_WIFI_PASSWORD, get_security()) == NSAPI_ERROR_OK) { if (wifi->disconnect() == NSAPI_ERROR_OK) { diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_secure.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_secure.cpp index ee3059f21c2..82f8e51261e 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_secure.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_secure.cpp @@ -28,6 +28,10 @@ using namespace utest::v1; void wifi_connect_secure(void) { WiFiInterface *wifi = get_interface(); + TEST_ASSERT(wifi); + if (wifi == NULL) { + return; + } // Driver shall cache the credentials char ssid[] = MBED_CONF_APP_WIFI_SECURE_SSID; diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_secure_fail.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_secure_fail.cpp index 72da4c03404..44d2793ad6b 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_secure_fail.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_secure_fail.cpp @@ -28,6 +28,10 @@ using namespace utest::v1; void wifi_connect_secure_fail(void) { WiFiInterface *wifi = get_interface(); + TEST_ASSERT(wifi); + if (wifi == NULL) { + return; + } TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->set_credentials(MBED_CONF_APP_WIFI_SECURE_SSID, "aaaaaaaa", get_security())); nsapi_error_t error; diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_get_rssi.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_get_rssi.cpp index 3cf5ab193f9..d6400a6b261 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_get_rssi.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_get_rssi.cpp @@ -28,6 +28,10 @@ using namespace utest::v1; void wifi_get_rssi(void) { WiFiInterface *wifi = get_interface(); + TEST_ASSERT(wifi); + if (wifi == NULL) { + return; + } TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->set_credentials(MBED_CONF_APP_WIFI_SECURE_SSID, MBED_CONF_APP_WIFI_PASSWORD, get_security())); diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_scan.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_scan.cpp index cfa86355b6e..1ae8e139a2b 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_scan.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_scan.cpp @@ -27,6 +27,10 @@ using namespace utest::v1; void wifi_scan(void) { WiFiInterface *wifi = get_interface(); + TEST_ASSERT(wifi); + if (wifi == NULL) { + return; + } WiFiAccessPoint ap[MBED_CONF_APP_MAX_SCAN_SIZE]; diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_scan_null.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_scan_null.cpp index 46751484c59..fc862e20cd1 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_scan_null.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_scan_null.cpp @@ -26,5 +26,9 @@ using namespace utest::v1; void wifi_scan_null(void) { WiFiInterface *wifi = get_interface(); + TEST_ASSERT(wifi); + if (wifi == NULL) { + return; + } TEST_ASSERT(wifi->scan(NULL, 0) >= 1); } diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_set_channel.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_set_channel.cpp index 09eaa23d7f4..cddd90a4bfc 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_set_channel.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_set_channel.cpp @@ -30,6 +30,10 @@ void wifi_set_channel(void) bool is_5Ghz = false; WiFiInterface *wifi = get_interface(); + TEST_ASSERT(wifi); + if (wifi == NULL) { + return; + } if (wifi->set_channel(1) == NSAPI_ERROR_UNSUPPORTED && wifi->set_channel(36) == NSAPI_ERROR_UNSUPPORTED) { TEST_IGNORE_MESSAGE("set_channel() not supported"); diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_set_credential.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_set_credential.cpp index b21e8f9443f..f7aae234b59 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_set_credential.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_set_credential.cpp @@ -26,6 +26,10 @@ using namespace utest::v1; void wifi_set_credential(void) { WiFiInterface *iface = get_interface(); + TEST_ASSERT(iface); + if (iface == NULL) { + return; + } nsapi_error_t error; error = iface->set_credentials(NULL, NULL, NSAPI_SECURITY_NONE);