mirror of
https://github.com/vanhoefm/fragattacks.git
synced 2024-11-25 00:38:24 -05:00
Check os_snprintf() result more consistently - automatic 2
This converts os_snprintf() result validation cases to use os_snprintf_error() where the comparison was 'res > size' instead of 'res >= size'. These changes were done automatically with spatch using the following semantic patch: @@ identifier E1; expression E2,E3,E4,E5,E6; statement S1; @@ ( E1 = os_snprintf(E2, E3, ...); | int E1 = os_snprintf(E2, E3, ...); | if (E5) E1 = os_snprintf(E2, E3, ...); else E1 = os_snprintf(E2, E3, ...); | if (E5) E1 = os_snprintf(E2, E3, ...); else if (E6) E1 = os_snprintf(E2, E3, ...); else E1 = 0; | if (E5) { ... E1 = os_snprintf(E2, E3, ...); } else { ... return -1; } | if (E5) { ... E1 = os_snprintf(E2, E3, ...); } else if (E6) { ... E1 = os_snprintf(E2, E3, ...); } else { ... return -1; } | if (E5) { ... E1 = os_snprintf(E2, E3, ...); } else { ... E1 = os_snprintf(E2, E3, ...); } ) ? os_free(E4); - if (E1 < 0 || \( E1 > E3 \| (size_t) E1 > E3 \| E1 > (int) E3 \)) + if (os_snprintf_error(E3, E1)) ( S1 | { ... } ) Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
d85e1fc8a5
commit
7bdd8981f7
@ -755,7 +755,7 @@ char * freq_range_list_str(const struct wpa_freq_range_list *list)
|
||||
res = os_snprintf(pos, end - pos, "%s%u-%u",
|
||||
i == 0 ? "" : ",",
|
||||
range->min, range->max);
|
||||
if (res < 0 || res > end - pos) {
|
||||
if (os_snprintf_error(end - pos, res)) {
|
||||
os_free(buf);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -642,7 +642,7 @@ static int ctrl_iface_get_capability_tdls(
|
||||
(wpa_s->drv_flags &
|
||||
WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
|
||||
"EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
|
||||
if (ret < 0 || (size_t) ret > buflen)
|
||||
if (os_snprintf_error(buflen, ret))
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
@ -5780,14 +5780,14 @@ static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
|
||||
"NOISE=%d\nFREQUENCY=%u\n",
|
||||
si.current_signal, si.current_txrate / 1000,
|
||||
si.current_noise, si.frequency);
|
||||
if (ret < 0 || ret > end - pos)
|
||||
if (os_snprintf_error(end - pos, ret))
|
||||
return -1;
|
||||
pos += ret;
|
||||
|
||||
if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
|
||||
ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
|
||||
channel_width_to_string(si.chanwidth));
|
||||
if (ret < 0 || ret > end - pos)
|
||||
if (os_snprintf_error(end - pos, ret))
|
||||
return -1;
|
||||
pos += ret;
|
||||
}
|
||||
@ -5796,7 +5796,7 @@ static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
|
||||
ret = os_snprintf(pos, end - pos,
|
||||
"CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
|
||||
si.center_frq1, si.center_frq2);
|
||||
if (ret < 0 || ret > end - pos)
|
||||
if (os_snprintf_error(end - pos, ret))
|
||||
return -1;
|
||||
pos += ret;
|
||||
}
|
||||
@ -5825,7 +5825,7 @@ static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
|
||||
|
||||
ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
|
||||
sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
|
||||
if (ret < 0 || (size_t) ret > buflen)
|
||||
if (os_snprintf_error(buflen, ret))
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
@ -465,7 +465,7 @@ dbus_bool_t wpa_dbus_dict_begin_array(DBusMessageIter *iter_dict,
|
||||
err = os_snprintf(array_type, sizeof(array_type),
|
||||
DBUS_TYPE_ARRAY_AS_STRING "%s",
|
||||
type);
|
||||
if (err < 0 || err > (int) sizeof(array_type))
|
||||
if (os_snprintf_error(sizeof(array_type), err))
|
||||
return FALSE;
|
||||
|
||||
if (!iter_dict || !iter_dict_entry || !iter_dict_val || !iter_array)
|
||||
|
Loading…
Reference in New Issue
Block a user