[PATCH] NAN: Fix maybe-uninitialized warnings in peer schedule handling

Jouni Malinen j at w1.fi
Thu Nov 19 14:06:13 PST 2026


On Tue, Oct 27, 2026 at 02:27:58AM +0000, Qingling Wu wrote:
> wpas_nan_set_peer_schedule_cb() declares `ret` without an initializer.
> If wpas_nan_set_peer_sched_chan() fails while building the local map
> list, the function jumps to `out` before any of the three assignments
> to `ret` (wpa_drv_sta_add(), wpa_drv_nan_config_peer_schedule(),
> wpa_drv_sta_remove()) are reached, so the final `return ret;` can
> return an uninitialized value. Initialize `ret` to 0 at declaration.

That feels like a wrong value to return in case
wpas_nan_set_peer_sched_chan() fails. Maybe the correct thing to do here
would be to do this instead:
    ret = wpas_nan_set_peer_sched_chan(...);
    if (ret < 0)
	goto out;

> nan_peer_set_sched() declares `map` inside a dl_list_for_each loop
> body without an initializer. When the committed schedule has no map
> entries (sched->n_maps == 0), the inner `for` loop body never
> executes and `map` is never assigned, even though the subsequent
> `if (i == sched->n_maps) continue;` check prevents it from actually
> being dereferenced. GCC's flow analysis cannot prove this invariant
> across the loop/break/continue structure and flags the memcpy use of
> `map` as possibly uninitialized. Initialize `map` to NULL at
> declaration to keep -Werror=maybe-uninitialized builds working.
> 
> Reproduced with arm-zephyr-eabi-gcc 14.3.0 -Og -Werror=maybe-uninitialized
> (Zephyr toolchain), no special build options required beyond -Werror,
> so this is not specific to the Zephyr build.

That does not show up in my build tests with gcc 13.3.0.. If a compiler
(or static analyzer..) cannot handle that, are you sure it can handle
the map == NULL not resulting in NULL pointer dereferencing here? It
would seem to be better to initialize map to NULL before the loop and
clear map to NULL if there is no map_id match at the end of the loop
iteration and then replace the i == sched->n_maps check with !map to
avoid this type of false reports.

-- 
Jouni Malinen                                            PGP id EFC895FA



More information about the Hostap mailing list