net: wifi_cred: Check null before access

We must do null check before trying to access the fields.

Fixes #81980
Coverify-CID: 434549

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This commit is contained in:
Jukka Rissanen 2024-11-26 13:37:29 +02:00 committed by Benjamin Cabé
commit 3aa0c8670e

View file

@ -154,13 +154,13 @@ int wifi_credentials_set_personal_struct(const struct wifi_credentials_personal
{
int ret;
if (creds->header.ssid_len > WIFI_SSID_MAX_LEN || creds->header.ssid_len == 0) {
LOG_ERR("Cannot set WiFi credentials, SSID has invalid format");
if (creds == NULL) {
LOG_ERR("Cannot set WiFi credentials, provided struct pointer cannot be NULL");
return -EINVAL;
}
if (creds == NULL) {
LOG_ERR("Cannot set WiFi credentials, provided struct pointer cannot be NULL");
if (creds->header.ssid_len > WIFI_SSID_MAX_LEN || creds->header.ssid_len == 0) {
LOG_ERR("Cannot set WiFi credentials, SSID has invalid format");
return -EINVAL;
}