]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Replace configuration int lists with int_arrays
authorJouni Malinen <jouni.malinen@oss.qualcomm.com>
Thu, 16 Oct 2025 20:23:12 +0000 (23:23 +0300)
committerJouni Malinen <j@w1.fi>
Thu, 16 Oct 2025 20:50:44 +0000 (23:50 +0300)
This cleans up implementation by getting rid of very similar
construction of a list of int values. hostapd used to terminate the
lists with -1 while int_array were terminated with 0. There are no cases
where 0 is needed to be included, so all these can be converted into the
existing int_array design.

Signed-off-by: Jouni Malinen <jouni.malinen@oss.qualcomm.com>
hostapd/config_file.c
src/ap/ap_config.c
src/ap/ap_config.h
src/ap/hw_features.c
src/drivers/driver_nl80211.c
src/utils/common.c
src/utils/common.h
tests/hwsim/test_wpas_mesh.py
wpa_supplicant/ap.c
wpa_supplicant/mesh.c

index 983dfad0a3f8f0e7ba1f9d4da22600f49bf42a6c..54ad77bcbf46acc32ddf5dd34152ce4eda7cedf4 100644 (file)
@@ -861,7 +861,7 @@ static int hostapd_parse_intlist(int **int_list, char *val)
                        break;
                pos = end + 1;
        }
-       list[count] = -1;
+       list[count] = 0;
 
        *int_list = list;
        return 0;
index ed1d13b70be003d0fd349a7fd0cfc6528297c900..d1d988b5fcac6a93cf41836704efd862d9704d0d 100644 (file)
@@ -1075,21 +1075,6 @@ int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
 }
 
 
-int hostapd_rate_found(int *list, int rate)
-{
-       int i;
-
-       if (list == NULL)
-               return 0;
-
-       for (i = 0; list[i] >= 0; i++)
-               if (list[i] == rate)
-                       return 1;
-
-       return 0;
-}
-
-
 int hostapd_vlan_valid(struct hostapd_vlan *vlan,
                       struct vlan_description *vlan_desc)
 {
index db5f75ef00d77513a0398e51835bac7d1d2419bb..44988d26135234c378b6cf8b810ecb0c4d27a7cc 100644 (file)
@@ -1382,7 +1382,6 @@ void hostapd_config_free_bss(struct hostapd_bss_config *conf);
 void hostapd_config_free(struct hostapd_config *conf);
 int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
                          const u8 *addr, struct vlan_description *vlan_id);
-int hostapd_rate_found(int *list, int rate);
 const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
                           const u8 *addr, const u8 *p2p_dev_addr,
                           const u8 *prev_psk, int *vlan_id);
index 1f80bdd24082c15b10aa6c11796fd08effc72acb..460b1d3ada09ecc1d7a8cbd51e218366f9475cb3 100644 (file)
@@ -198,10 +198,10 @@ int hostapd_prepare_rates(struct hostapd_iface *iface,
                          struct hostapd_hw_modes *mode)
 {
        int i, num_basic_rates = 0;
-       int basic_rates_a[] = { 60, 120, 240, -1 };
-       int basic_rates_b[] = { 10, 20, -1 };
-       int basic_rates_g[] = { 10, 20, 55, 110, -1 };
-       int *basic_rates;
+       int basic_rates_a[] = { 60, 120, 240, 0 };
+       int basic_rates_b[] = { 10, 20, 0 };
+       int basic_rates_g[] = { 10, 20, 55, 110, 0 };
+       const int *basic_rates;
 
        if (iface->conf->basic_rates)
                basic_rates = iface->conf->basic_rates;
@@ -221,15 +221,8 @@ int hostapd_prepare_rates(struct hostapd_iface *iface,
                return -1;
        }
 
-       i = 0;
-       while (basic_rates[i] >= 0)
-               i++;
-       if (i)
-               i++; /* -1 termination */
        os_free(iface->basic_rates);
-       iface->basic_rates = os_malloc(i * sizeof(int));
-       if (iface->basic_rates)
-               os_memcpy(iface->basic_rates, basic_rates, i * sizeof(int));
+       iface->basic_rates = int_array_dup(basic_rates);
 
        os_free(iface->current_rates);
        iface->num_rates = 0;
@@ -246,13 +239,13 @@ int hostapd_prepare_rates(struct hostapd_iface *iface,
                struct hostapd_rate_data *rate;
 
                if (iface->conf->supported_rates &&
-                   !hostapd_rate_found(iface->conf->supported_rates,
+                   !int_array_includes(iface->conf->supported_rates,
                                        mode->rates[i]))
                        continue;
 
                rate = &iface->current_rates[iface->num_rates];
                rate->rate = mode->rates[i];
-               if (hostapd_rate_found(basic_rates, rate->rate)) {
+               if (int_array_includes(basic_rates, rate->rate)) {
                        rate->flags |= HOSTAPD_RATE_BASIC;
                        num_basic_rates++;
                }
index f31c54dc40d739ac115e66d3ca5196440a3e98e7..bf9aeb22bb93f2e812dd8f57141105e8ece64679 100644 (file)
@@ -4747,7 +4747,7 @@ static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates)
        if (!basic_rates)
                return 0;
 
-       for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++)
+       for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] > 0; i++)
                rates[rates_len++] = basic_rates[i] / 5;
 
        return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates);
index eb5a68b4957d5fec9b1fc263bb8e84c9db431322..d90bdb989bfe39a6e52f8dbb19e8cb76bb8e988f 100644 (file)
@@ -1025,6 +1025,14 @@ bool int_array_equal(const int *a, const int *b)
 }
 
 
+int * int_array_dup(const int *a)
+{
+       if (!a)
+               return NULL;
+       return os_memdup(a, (int_array_len(a) + 1) * sizeof(int));
+}
+
+
 void str_clear_free(char *str)
 {
        if (str) {
index d7b3600f27e474c8134bf2e491ff2da1b0259ff6..835818dfb9d224ae186f9ca925d599c806a0f427 100644 (file)
@@ -596,6 +596,7 @@ void int_array_sort_unique(int *a);
 void int_array_add_unique(int **res, int a);
 bool int_array_includes(const int *arr, int val);
 bool int_array_equal(const int *a, const int *b);
+int * int_array_dup(const int *a);
 
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
 
index 1aa3b5c17433527945575bf409c94b6b3d0eb58d..3be63fe0b2702bf0102d08a6b521989ef47ae3e7 100644 (file)
@@ -1780,7 +1780,7 @@ def test_mesh_oom(dev, apdev):
         if ev is None:
             raise Exception("Init failure not reported")
 
-    with alloc_fail(dev[0], 2, "=wpa_supplicant_mesh_init"):
+    with alloc_fail(dev[0], 1, "int_array_dup;wpa_supplicant_mesh_init"):
         add_open_mesh_network(dev[0], basic_rates="60 120 240")
         ev = dev[0].wait_event(["Failed to init mesh"])
         if ev is None:
index 7cf557f0877e7b5c541f63c1d4f2c63a6ce49a07..eddc40ad20da4975f4d5f0e1d035daec2f93362f 100644 (file)
@@ -521,7 +521,7 @@ static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
                        list[0] = 60;
                        list[1] = 120;
                        list[2] = 240;
-                       list[3] = -1;
+                       list[3] = 0;
                }
                conf->basic_rates = list;
 
@@ -535,7 +535,7 @@ static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
                        list[5] = 360;
                        list[6] = 480;
                        list[7] = 540;
-                       list[8] = -1;
+                       list[8] = 0;
                }
                conf->supported_rates = list;
        }
index 297d644e5621d19b8806355dfaf3545a43317b5a..8f2c3c5f066249ef2b4ceb0575816653c4ea3c2e 100644 (file)
@@ -150,30 +150,12 @@ static struct mesh_conf * mesh_config_create(struct wpa_supplicant *wpa_s,
 }
 
 
-static void wpas_mesh_copy_groups(struct hostapd_data *bss,
-                                 struct wpa_supplicant *wpa_s)
-{
-       int num_groups;
-       size_t groups_size;
-
-       for (num_groups = 0; wpa_s->conf->sae_groups[num_groups] > 0;
-            num_groups++)
-               ;
-
-       groups_size = (num_groups + 1) * sizeof(wpa_s->conf->sae_groups[0]);
-       bss->conf->sae_groups = os_malloc(groups_size);
-       if (bss->conf->sae_groups)
-               os_memcpy(bss->conf->sae_groups, wpa_s->conf->sae_groups,
-                         groups_size);
-}
-
-
 static int wpas_mesh_init_rsn(struct wpa_supplicant *wpa_s)
 {
        struct hostapd_iface *ifmsh = wpa_s->ifmsh;
        struct wpa_ssid *ssid = wpa_s->current_ssid;
        struct hostapd_data *bss = ifmsh->bss[0];
-       static int default_groups[] = { 19, 20, 21, 25, 26, -1 };
+       static int default_groups[] = { 19, 20, 21, 25, 26, 0 };
        const char *password;
        size_t len;
 
@@ -189,14 +171,12 @@ static int wpas_mesh_init_rsn(struct wpa_supplicant *wpa_s)
        bss->conf->wpa = ssid->proto;
        bss->conf->wpa_key_mgmt = ssid->key_mgmt;
 
-       if (wpa_s->conf->sae_groups && wpa_s->conf->sae_groups[0] > 0) {
-               wpas_mesh_copy_groups(bss, wpa_s);
-       } else {
-               bss->conf->sae_groups = os_memdup(default_groups,
-                                                 sizeof(default_groups));
-               if (!bss->conf->sae_groups)
-                       return -1;
-       }
+       if (wpa_s->conf->sae_groups && wpa_s->conf->sae_groups[0] > 0)
+               bss->conf->sae_groups = int_array_dup(wpa_s->conf->sae_groups);
+       else
+               bss->conf->sae_groups = int_array_dup(default_groups);
+       if (!bss->conf->sae_groups)
+               return -1;
 
        len = os_strlen(password);
        bss->conf->ssid.wpa_passphrase = dup_binstr(password, len);
@@ -386,8 +366,7 @@ static int wpa_supplicant_mesh_init(struct wpa_supplicant *wpa_s,
        struct hostapd_data *bss;
        struct hostapd_config *conf;
        struct mesh_conf *mconf;
-       int basic_rates_erp[] = { 10, 20, 55, 60, 110, 120, 240, -1 };
-       int rate_len;
+       int basic_rates_erp[] = { 10, 20, 55, 60, 110, 120, 240, 0 };
        int frequency;
        bool is_dfs;
        u8 chan;
@@ -554,18 +533,9 @@ static int wpa_supplicant_mesh_init(struct wpa_supplicant *wpa_s,
                                goto out_free;
                }
        } else {
-               rate_len = 0;
-               while (1) {
-                       if (ssid->mesh_basic_rates[rate_len] < 1)
-                               break;
-                       rate_len++;
-               }
-               conf->basic_rates = os_calloc(rate_len + 1, sizeof(int));
+               conf->basic_rates = int_array_dup(ssid->mesh_basic_rates);
                if (conf->basic_rates == NULL)
                        goto out_free;
-               os_memcpy(conf->basic_rates, ssid->mesh_basic_rates,
-                         rate_len * sizeof(int));
-               conf->basic_rates[rate_len] = -1;
        }
 
        /* While it can enhance performance to switch the primary channel, which