Check os_snprintf() result more consistently - automatic 1
This converts os_snprintf() result validation cases to use os_snprintf_error() where the exact rule used in os_snprintf_error() was used. 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 \| (unsigned int) 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
a80ba67a26
commit
d85e1fc8a5
49 changed files with 343 additions and 343 deletions
|
@ -36,7 +36,7 @@ static int hostapd_get_sta_tx_rx(struct hostapd_data *hapd,
|
|||
"rx_bytes=%lu\ntx_bytes=%lu\n",
|
||||
data.rx_packets, data.tx_packets,
|
||||
data.rx_bytes, data.tx_bytes);
|
||||
if (ret < 0 || (size_t) ret >= buflen)
|
||||
if (os_snprintf_error(buflen, ret))
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ static int hostapd_get_sta_conn_time(struct sta_info *sta,
|
|||
|
||||
ret = os_snprintf(buf, buflen, "connected_time=%u\n",
|
||||
(unsigned int) age.sec);
|
||||
if (ret < 0 || (size_t) ret >= buflen)
|
||||
if (os_snprintf_error(buflen, ret))
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ static int hostapd_ctrl_iface_sta_mib(struct hostapd_data *hapd,
|
|||
len = 0;
|
||||
ret = os_snprintf(buf + len, buflen - len, MACSTR "\nflags=",
|
||||
MAC2STR(sta->addr));
|
||||
if (ret < 0 || (size_t) ret >= buflen - len)
|
||||
if (os_snprintf_error(buflen - len, ret))
|
||||
return len;
|
||||
len += ret;
|
||||
|
||||
|
@ -104,7 +104,7 @@ static int hostapd_ctrl_iface_sta_mib(struct hostapd_data *hapd,
|
|||
ret = os_snprintf(buf + len, buflen - len, "\naid=%d\ncapability=0x%x\n"
|
||||
"listen_interval=%d\nsupported_rates=",
|
||||
sta->aid, sta->capability, sta->listen_interval);
|
||||
if (ret < 0 || (size_t) ret >= buflen - len)
|
||||
if (os_snprintf_error(buflen - len, ret))
|
||||
return len;
|
||||
len += ret;
|
||||
|
||||
|
@ -112,14 +112,14 @@ static int hostapd_ctrl_iface_sta_mib(struct hostapd_data *hapd,
|
|||
ret = os_snprintf(buf + len, buflen - len, "%02x%s",
|
||||
sta->supported_rates[i],
|
||||
i + 1 < sta->supported_rates_len ? " " : "");
|
||||
if (ret < 0 || (size_t) ret >= buflen - len)
|
||||
if (os_snprintf_error(buflen - len, ret))
|
||||
return len;
|
||||
len += ret;
|
||||
}
|
||||
|
||||
ret = os_snprintf(buf + len, buflen - len, "\ntimeout_next=%s\n",
|
||||
timeout_next_str(sta->timeout_next));
|
||||
if (ret < 0 || (size_t) ret >= buflen - len)
|
||||
if (os_snprintf_error(buflen - len, ret))
|
||||
return len;
|
||||
len += ret;
|
||||
|
||||
|
@ -164,7 +164,7 @@ int hostapd_ctrl_iface_sta(struct hostapd_data *hapd, const char *txtaddr,
|
|||
|
||||
if (hwaddr_aton(txtaddr, addr)) {
|
||||
ret = os_snprintf(buf, buflen, "FAIL\n");
|
||||
if (ret < 0 || (size_t) ret >= buflen)
|
||||
if (os_snprintf_error(buflen, ret))
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ int hostapd_ctrl_iface_sta_next(struct hostapd_data *hapd, const char *txtaddr,
|
|||
if (hwaddr_aton(txtaddr, addr) ||
|
||||
(sta = ap_get_sta(hapd, addr)) == NULL) {
|
||||
ret = os_snprintf(buf, buflen, "FAIL\n");
|
||||
if (ret < 0 || (size_t) ret >= buflen)
|
||||
if (os_snprintf_error(buflen, ret))
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
@ -422,7 +422,7 @@ int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf,
|
|||
iface->num_sta_ht40_intolerant,
|
||||
iface->olbc_ht,
|
||||
iface->ht_op_mode);
|
||||
if (ret < 0 || (size_t) ret >= buflen - len)
|
||||
if (os_snprintf_error(buflen - len, ret))
|
||||
return len;
|
||||
len += ret;
|
||||
|
||||
|
@ -444,7 +444,7 @@ int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf,
|
|||
iface->dfs_cac_ms / 1000,
|
||||
left_time);
|
||||
}
|
||||
if (ret < 0 || (size_t) ret >= buflen - len)
|
||||
if (os_snprintf_error(buflen - len, ret))
|
||||
return len;
|
||||
len += ret;
|
||||
|
||||
|
@ -463,7 +463,7 @@ int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf,
|
|||
iface->conf->vht_oper_chwidth,
|
||||
iface->conf->vht_oper_centr_freq_seg0_idx,
|
||||
iface->conf->vht_oper_centr_freq_seg1_idx);
|
||||
if (ret < 0 || (size_t) ret >= buflen - len)
|
||||
if (os_snprintf_error(buflen - len, ret))
|
||||
return len;
|
||||
len += ret;
|
||||
|
||||
|
@ -480,7 +480,7 @@ int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf,
|
|||
wpa_ssid_txt(bss->conf->ssid.ssid,
|
||||
bss->conf->ssid.ssid_len),
|
||||
(int) i, bss->num_sta);
|
||||
if (ret < 0 || (size_t) ret >= buflen - len)
|
||||
if (os_snprintf_error(buflen - len, ret))
|
||||
return len;
|
||||
len += ret;
|
||||
}
|
||||
|
|
|
@ -2359,7 +2359,7 @@ int ieee802_1x_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
|
|||
sta->aid,
|
||||
EAPOL_VERSION,
|
||||
sm->initialize);
|
||||
if (ret < 0 || (size_t) ret >= buflen - len)
|
||||
if (os_snprintf_error(buflen - len, ret))
|
||||
return len;
|
||||
len += ret;
|
||||
|
||||
|
@ -2387,7 +2387,7 @@ int ieee802_1x_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
|
|||
sm->reAuthPeriod,
|
||||
bool_txt(sm->reAuthEnabled),
|
||||
bool_txt(sm->keyTxEnabled));
|
||||
if (ret < 0 || (size_t) ret >= buflen - len)
|
||||
if (os_snprintf_error(buflen - len, ret))
|
||||
return len;
|
||||
len += ret;
|
||||
|
||||
|
@ -2417,7 +2417,7 @@ int ieee802_1x_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
|
|||
sm->dot1xAuthEapLengthErrorFramesRx,
|
||||
sm->dot1xAuthLastEapolFrameVersion,
|
||||
MAC2STR(sm->addr));
|
||||
if (ret < 0 || (size_t) ret >= buflen - len)
|
||||
if (os_snprintf_error(buflen - len, ret))
|
||||
return len;
|
||||
len += ret;
|
||||
|
||||
|
@ -2455,7 +2455,7 @@ int ieee802_1x_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
|
|||
sm->backendOtherRequestsToSupplicant,
|
||||
sm->backendAuthSuccesses,
|
||||
sm->backendAuthFails);
|
||||
if (ret < 0 || (size_t) ret >= buflen - len)
|
||||
if (os_snprintf_error(buflen - len, ret))
|
||||
return len;
|
||||
len += ret;
|
||||
|
||||
|
@ -2477,7 +2477,7 @@ int ieee802_1x_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
|
|||
1 : 2,
|
||||
(unsigned int) diff.sec,
|
||||
sm->identity);
|
||||
if (ret < 0 || (size_t) ret >= buflen - len)
|
||||
if (os_snprintf_error(buflen - len, ret))
|
||||
return len;
|
||||
len += ret;
|
||||
|
||||
|
@ -2490,7 +2490,7 @@ int ieee802_1x_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
|
|||
name1 ? name1 : "",
|
||||
sm->eap_type_supp,
|
||||
name2 ? name2 : "");
|
||||
if (ret < 0 || (size_t) ret >= buflen - len)
|
||||
if (os_snprintf_error(buflen - len, ret))
|
||||
return len;
|
||||
len += ret;
|
||||
|
||||
|
|
|
@ -2970,7 +2970,7 @@ int wpa_get_mib(struct wpa_authenticator *wpa_auth, char *buf, size_t buflen)
|
|||
wpa_bool_txt(preauth),
|
||||
wpa_bool_txt(wpa_auth->conf.wpa & WPA_PROTO_RSN),
|
||||
wpa_bool_txt(wpa_auth->conf.rsn_preauth));
|
||||
if (ret < 0 || (size_t) ret >= buflen - len)
|
||||
if (os_snprintf_error(buflen - len, ret))
|
||||
return len;
|
||||
len += ret;
|
||||
|
||||
|
@ -3020,7 +3020,7 @@ int wpa_get_mib(struct wpa_authenticator *wpa_auth, char *buf, size_t buflen)
|
|||
RSN_SUITE_ARG(wpa_auth->dot11RSNAGroupCipherRequested),
|
||||
wpa_auth->dot11RSNATKIPCounterMeasuresInvoked,
|
||||
wpa_auth->dot11RSNA4WayHandshakeFailures);
|
||||
if (ret < 0 || (size_t) ret >= buflen - len)
|
||||
if (os_snprintf_error(buflen - len, ret))
|
||||
return len;
|
||||
len += ret;
|
||||
|
||||
|
@ -3030,7 +3030,7 @@ int wpa_get_mib(struct wpa_authenticator *wpa_auth, char *buf, size_t buflen)
|
|||
/* Private MIB */
|
||||
ret = os_snprintf(buf + len, buflen - len, "hostapdWPAGroupState=%d\n",
|
||||
wpa_auth->group->wpa_group_state);
|
||||
if (ret < 0 || (size_t) ret >= buflen - len)
|
||||
if (os_snprintf_error(buflen - len, ret))
|
||||
return len;
|
||||
len += ret;
|
||||
|
||||
|
@ -3072,7 +3072,7 @@ int wpa_get_mib_sta(struct wpa_state_machine *sm, char *buf, size_t buflen)
|
|||
RSN_SUITE_ARG(pairwise),
|
||||
sm->dot11RSNAStatsTKIPLocalMICFailures,
|
||||
sm->dot11RSNAStatsTKIPRemoteMICFailures);
|
||||
if (ret < 0 || (size_t) ret >= buflen - len)
|
||||
if (os_snprintf_error(buflen - len, ret))
|
||||
return len;
|
||||
len += ret;
|
||||
|
||||
|
@ -3082,7 +3082,7 @@ int wpa_get_mib_sta(struct wpa_state_machine *sm, char *buf, size_t buflen)
|
|||
"hostapdWPAPTKGroupState=%d\n",
|
||||
sm->wpa_ptk_state,
|
||||
sm->wpa_ptk_group_state);
|
||||
if (ret < 0 || (size_t) ret >= buflen - len)
|
||||
if (os_snprintf_error(buflen - len, ret))
|
||||
return len;
|
||||
len += ret;
|
||||
|
||||
|
|
|
@ -1583,7 +1583,7 @@ int hostapd_wps_ap_pin_set(struct hostapd_data *hapd, const char *pin,
|
|||
int ret;
|
||||
|
||||
ret = os_snprintf(data.pin_txt, sizeof(data.pin_txt), "%s", pin);
|
||||
if (ret < 0 || ret >= (int) sizeof(data.pin_txt))
|
||||
if (os_snprintf_error(sizeof(data.pin_txt), ret))
|
||||
return -1;
|
||||
data.timeout = timeout;
|
||||
return hostapd_wps_for_each(hapd, wps_ap_pin_set, &data);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue