]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
UBSan: Avoid integer overflow in a loop index counter
authorJouni Malinen <j@w1.fi>
Sat, 23 Feb 2019 14:28:16 +0000 (16:28 +0200)
committerJouni Malinen <j@w1.fi>
Mon, 25 Feb 2019 17:48:49 +0000 (19:48 +0200)
Split the check and decrementation into separate steps to avoid an
unnecessary UBSan warning.

hostapd.c:1895:14: runtime error: unsigned integer overflow: 0 - 1 cannot be represented in type 'size_t' (aka 'unsigned long')

Signed-off-by: Jouni Malinen <j@w1.fi>
src/ap/hostapd.c

index 16c030f36ab2ea306343a6e24c91b0b4818c9084..5dcec47e1aaaffa2c10e51cac3a6e386a3702652 100644 (file)
@@ -1888,11 +1888,14 @@ static int hostapd_setup_interface_complete_sync(struct hostapd_iface *iface,
                if (j)
                        os_memcpy(hapd->own_addr, prev_addr, ETH_ALEN);
                if (hostapd_setup_bss(hapd, j == 0)) {
-                       do {
+                       for (;;) {
                                hapd = iface->bss[j];
                                hostapd_bss_deinit_no_free(hapd);
                                hostapd_free_hapd_data(hapd);
-                       } while (j-- > 0);
+                               if (j == 0)
+                                       break;
+                               j--;
+                       }
                        goto fail;
                }
                if (is_zero_ether_addr(hapd->conf->bssid))