mirror of
https://github.com/vanhoefm/fragattacks.git
synced 2024-11-28 18:28:23 -05:00
P2P: Check os_get_random() return value more consistently
In theory, this call could fail, so check the return value before using the received data. These specific cases would not really care much about the failures, but this keeps the code more consistent and keeps static analyzer warnings more useful. (CID 72678, CID 72679, CID 72680, CID 72683, CID 72689, CID 72698, CID 72703) Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
54461f3e03
commit
df2508d7a8
@ -259,7 +259,8 @@ static void p2p_listen_in_find(struct p2p_data *p2p, int dev_disc)
|
||||
return;
|
||||
}
|
||||
|
||||
os_get_random((u8 *) &r, sizeof(r));
|
||||
if (os_get_random((u8 *) &r, sizeof(r)) < 0)
|
||||
r = 0;
|
||||
tu = (r % ((p2p->max_disc_int - p2p->min_disc_int) + 1) +
|
||||
p2p->min_disc_int) * 100;
|
||||
if (p2p->max_disc_tu >= 0 && tu > (unsigned int) p2p->max_disc_tu)
|
||||
@ -2480,7 +2481,8 @@ struct p2p_data * p2p_init(const struct p2p_config *cfg)
|
||||
p2p->max_disc_int = 3;
|
||||
p2p->max_disc_tu = -1;
|
||||
|
||||
os_get_random(&p2p->next_tie_breaker, 1);
|
||||
if (os_get_random(&p2p->next_tie_breaker, 1) < 0)
|
||||
p2p->next_tie_breaker = 0;
|
||||
p2p->next_tie_breaker &= 0x01;
|
||||
if (cfg->sd_request)
|
||||
p2p->dev_capab |= P2P_DEV_CAPAB_SERVICE_DISCOVERY;
|
||||
@ -3003,7 +3005,8 @@ static void p2p_go_neg_req_cb(struct p2p_data *p2p, int success)
|
||||
* make it less likely to hit cases where we could end up in
|
||||
* sync with peer not listening.
|
||||
*/
|
||||
os_get_random((u8 *) &r, sizeof(r));
|
||||
if (os_get_random((u8 *) &r, sizeof(r)) < 0)
|
||||
r = 0;
|
||||
timeout += r % 100000;
|
||||
}
|
||||
p2p_set_timeout(p2p, 0, timeout);
|
||||
|
@ -441,7 +441,8 @@ void p2p_channels_dump(struct p2p_data *p2p, const char *title,
|
||||
static u8 p2p_channel_pick_random(const u8 *channels, unsigned int num_channels)
|
||||
{
|
||||
unsigned int r;
|
||||
os_get_random((u8 *) &r, sizeof(r));
|
||||
if (os_get_random((u8 *) &r, sizeof(r)) < 0)
|
||||
r = 0;
|
||||
r %= num_channels;
|
||||
return channels[r];
|
||||
}
|
||||
|
@ -3927,7 +3927,8 @@ int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s)
|
||||
* Pick one of the social channels randomly as the listen
|
||||
* channel.
|
||||
*/
|
||||
os_get_random((u8 *) &r, sizeof(r));
|
||||
if (os_get_random((u8 *) &r, sizeof(r)) < 0)
|
||||
return -1;
|
||||
p2p.channel = 1 + (r % 3) * 5;
|
||||
p2p.channel_forced = 0;
|
||||
}
|
||||
@ -3947,7 +3948,8 @@ int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s)
|
||||
* Use random operation channel from (1, 6, 11) if no other
|
||||
* preference is indicated.
|
||||
*/
|
||||
os_get_random((u8 *) &r, sizeof(r));
|
||||
if (os_get_random((u8 *) &r, sizeof(r)) < 0)
|
||||
return -1;
|
||||
p2p.op_channel = 1 + (r % 3) * 5;
|
||||
p2p.cfg_op_channel = 0;
|
||||
wpa_printf(MSG_DEBUG, "P2P: Random operating channel: "
|
||||
@ -5030,7 +5032,8 @@ static int wpas_p2p_select_go_freq(struct wpa_supplicant *wpa_s, int freq)
|
||||
wpa_printf(MSG_DEBUG, "P2P: Use best 2.4 GHz band "
|
||||
"channel: %d MHz", freq);
|
||||
} else {
|
||||
os_get_random((u8 *) &r, sizeof(r));
|
||||
if (os_get_random((u8 *) &r, sizeof(r)) < 0)
|
||||
return -1;
|
||||
freq = 2412 + (r % 3) * 25;
|
||||
wpa_printf(MSG_DEBUG, "P2P: Use random 2.4 GHz band "
|
||||
"channel: %d MHz", freq);
|
||||
@ -5047,7 +5050,8 @@ static int wpas_p2p_select_go_freq(struct wpa_supplicant *wpa_s, int freq)
|
||||
wpa_printf(MSG_DEBUG, "P2P: Use best 5 GHz band "
|
||||
"channel: %d MHz", freq);
|
||||
} else {
|
||||
os_get_random((u8 *) &r, sizeof(r));
|
||||
if (os_get_random((u8 *) &r, sizeof(r)) < 0)
|
||||
return -1;
|
||||
freq = 5180 + (r % 4) * 20;
|
||||
if (!p2p_supported_freq_go(wpa_s->global->p2p, freq)) {
|
||||
wpa_printf(MSG_DEBUG, "P2P: Could not select "
|
||||
@ -6329,7 +6333,9 @@ void wpas_p2p_update_config(struct wpa_supplicant *wpa_s)
|
||||
* Pick one of the social channels randomly as the
|
||||
* listen channel.
|
||||
*/
|
||||
os_get_random((u8 *) &r, sizeof(r));
|
||||
if (os_get_random((u8 *) &r, sizeof(r)) < 0)
|
||||
channel = 1;
|
||||
else
|
||||
channel = 1 + (r % 3) * 5;
|
||||
channel_forced = 0;
|
||||
}
|
||||
@ -6354,7 +6360,9 @@ void wpas_p2p_update_config(struct wpa_supplicant *wpa_s)
|
||||
* Use random operation channel from (1, 6, 11)
|
||||
*if no other preference is indicated.
|
||||
*/
|
||||
os_get_random((u8 *) &r, sizeof(r));
|
||||
if (os_get_random((u8 *) &r, sizeof(r)) < 0)
|
||||
op_channel = 1;
|
||||
else
|
||||
op_channel = 1 + (r % 3) * 5;
|
||||
cfg_op_channel = 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user