Add NULL check when setting psk or pmk 43/236943/2
authorCheoleun Moon <chleun.moon@samsung.com>
Tue, 23 Jun 2020 10:22:37 +0000 (19:22 +0900)
committerCheoleun Moon <chleun.moon@samsung.com>
Tue, 23 Jun 2020 10:24:16 +0000 (19:24 +0900)
Change-Id: If6c86eec01e591672efcd992d3cc29057522a237

src/wifi-aware-data-path.c
tests/unittest/wifi-aware-data-path-unittest.cpp
tests/unittest/wifi-aware-session-unittest.cpp

index 05a93b473b78992cd30510b1000cce6929e25d2a..19db59fb1f4dd207b4fd9965b5cc324092e7aa0a 100644 (file)
@@ -148,10 +148,10 @@ int _wifi_aware_data_path_set_psk(wifi_aware_data_path_h data_path, const char *
        __WIFI_AWARE_FUNC_ENTER__;
 
        RET_VAL_IF(data_path == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "data_path is NULL");
-
        wifi_aware_data_path_s *ndp = (wifi_aware_data_path_s *)data_path;
        RET_VAL_IF(ndp->security_type != WIFI_AWARE_SECURITY_TYPE_PSK,
                WIFI_AWARE_ERROR_INVALID_OPERATION, "security type is not WIFI_AWARE_SECURITY_TYPE_PSK");
+       RET_VAL_IF(psk == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "psk is NULL");
 
        if (!__is_valid_psk_len(psk)) {
                WIFI_AWARE_LOGE("The length of the password should be equal to or greater than 8 and less than 64");
@@ -170,6 +170,7 @@ int _wifi_aware_data_path_set_pmk(wifi_aware_data_path_h data_path, const unsign
        wifi_aware_data_path_s *ndp = (wifi_aware_data_path_s *)data_path;
        RET_VAL_IF(ndp->security_type != WIFI_AWARE_SECURITY_TYPE_PMK,
                WIFI_AWARE_ERROR_INVALID_OPERATION, "security type is not WIFI_AWARE_SECURITY_TYPE_PMK");
+       RET_VAL_IF(pmk == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "pmk is NULL");
 
        ndp->pmk_len = WIFI_AWARE_PMK_LEN;
        memcpy(ndp->pmk, pmk, ndp->pmk_len);
index 1fc747e80f216b28b759095a04ba587f0fb86432..665f20f98f2fae47d9f0e22a615afa4d6c705eb2 100644 (file)
@@ -91,6 +91,9 @@ TEST_F(WifiAwareDataPath, wifi_aware_data_path_set_psk_n)
 
        ret = wifi_aware_data_path_set_psk(g_data_path, "123");
        CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_PARAMETER, ret, "wifi_aware_data_path_set_psk");
+
+       ret = wifi_aware_data_path_set_psk(g_data_path, NULL);
+       CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_PARAMETER, ret, "wifi_aware_data_path_set_psk");
 }
 
 TEST_F(WifiAwareDataPath, wifi_aware_data_path_set_pmk_p)
@@ -110,6 +113,9 @@ TEST_F(WifiAwareDataPath, wifi_aware_data_path_set_pmk_n)
 
        wifi_aware_data_path_set_security(g_data_path, WIFI_AWARE_SECURITY_TYPE_PMK);
 
+       ret = wifi_aware_data_path_set_pmk(g_data_path, NULL);
+       CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_PARAMETER, ret, "wifi_aware_data_path_set_pmk");
+
        ret = wifi_aware_data_path_set_pmk(NULL, NULL);
        CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_PARAMETER, ret, "wifi_aware_data_path_set_pmk");
 }
index 572b2b9c3eca8a3a72cd1f0456dc16d47e913aa9..e18df945f410b912c525457a6be87be5af77aba7 100644 (file)
@@ -48,13 +48,13 @@ void WifiAwareSession::__discovered_cb(wifi_aware_session_h session, wifi_aware_
 }
 
 void WifiAwareSession::__send_reply(wifi_aware_session_h session,
-        wifi_aware_error_e error, void *user_data)
+               wifi_aware_error_e error, void *user_data)
 {
 }
 
 
 void WifiAwareSession::__received_cb(wifi_aware_session_h session, wifi_aware_peer_h peer,
-        const unsigned char *message, size_t len, void *user_data)
+               const unsigned char *message, size_t len, void *user_data)
 {
        g_message_received = true;
        QUIT_GMAIN_LOOP;