hostapd: clear ucode interface/bss resource pointers
authorFelix Fietkau <nbd@nbd.name>
Tue, 12 Sep 2023 11:32:40 +0000 (13:32 +0200)
committerFelix Fietkau <nbd@nbd.name>
Tue, 12 Sep 2023 12:09:58 +0000 (14:09 +0200)
Avoids potential use-after-free bugs

Signed-off-by: Felix Fietkau <nbd@nbd.name>
package/network/services/hostapd/src/src/utils/ucode.c

index 896ef46e1f6f13e2b25b5c38c51c285fa9587efa..2beeb9a7ff6b6a9bec976efd331e8d88465c3df7 100644 (file)
@@ -298,9 +298,15 @@ uc_value_t *wpa_ucode_registry_get(uc_value_t *reg, int idx)
 uc_value_t *wpa_ucode_registry_remove(uc_value_t *reg, int idx)
 {
        uc_value_t *val = wpa_ucode_registry_get(reg, idx);
+       void **dataptr;
 
-       if (val)
-               ucv_array_set(reg, idx - 1, NULL);
+       if (!val)
+               return NULL;
+
+       ucv_array_set(reg, idx - 1, NULL);
+       dataptr = ucv_resource_dataptr(val, NULL);
+       if (dataptr)
+               *dataptr = NULL;
 
        return val;
 }