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>
master
Jouni Malinen 10 years ago
parent a80ba67a26
commit d85e1fc8a5

@ -246,14 +246,14 @@ static int hostapd_ctrl_iface_wps_check_pin(
if (!wps_pin_valid(pin_val)) {
wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
if (ret < 0 || (size_t) ret >= buflen)
if (os_snprintf_error(buflen, ret))
return -1;
return ret;
}
}
ret = os_snprintf(buf, buflen, "%s", pin);
if (ret < 0 || (size_t) ret >= buflen)
if (os_snprintf_error(buflen, ret))
return -1;
return ret;
@ -584,7 +584,7 @@ static int hostapd_ctrl_iface_wps_get_status(struct hostapd_data *hapd,
ret = os_snprintf(pos, end - pos, "PBC Status: %s\n",
pbc_status_str(hapd->wps_stats.pbc_status));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
@ -594,7 +594,7 @@ static int hostapd_ctrl_iface_wps_get_status(struct hostapd_data *hapd,
(hapd->wps_stats.status == WPS_STATUS_FAILURE ?
"Failed" : "None")));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
@ -605,7 +605,7 @@ static int hostapd_ctrl_iface_wps_get_status(struct hostapd_data *hapd,
"Failure Reason: %s\n",
wps_ei_str(hapd->wps_stats.failure_reason));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -614,7 +614,7 @@ static int hostapd_ctrl_iface_wps_get_status(struct hostapd_data *hapd,
ret = os_snprintf(pos, end - pos, "Peer Address: " MACSTR "\n",
MAC2STR(hapd->wps_stats.peer_addr));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -1067,7 +1067,7 @@ static int hostapd_ctrl_iface_get_config(struct hostapd_data *hapd,
MAC2STR(hapd->own_addr),
wpa_ssid_txt(hapd->conf->ssid.ssid,
hapd->conf->ssid.ssid_len));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
@ -1076,7 +1076,7 @@ static int hostapd_ctrl_iface_get_config(struct hostapd_data *hapd,
hapd->conf->wps_state == 0 ? "disabled" :
(hapd->conf->wps_state == 1 ? "not configured" :
"configured"));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
@ -1084,7 +1084,7 @@ static int hostapd_ctrl_iface_get_config(struct hostapd_data *hapd,
hapd->conf->ssid.wpa_passphrase) {
ret = os_snprintf(pos, end - pos, "passphrase=%s\n",
hapd->conf->ssid.wpa_passphrase);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -1096,7 +1096,7 @@ static int hostapd_ctrl_iface_get_config(struct hostapd_data *hapd,
wpa_snprintf_hex(hex, sizeof(hex),
hapd->conf->ssid.wpa_psk->psk, PMK_LEN);
ret = os_snprintf(pos, end - pos, "psk=%s\n", hex);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -1104,39 +1104,39 @@ static int hostapd_ctrl_iface_get_config(struct hostapd_data *hapd,
if (hapd->conf->wpa && hapd->conf->wpa_key_mgmt) {
ret = os_snprintf(pos, end - pos, "key_mgmt=");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK) {
ret = os_snprintf(pos, end - pos, "WPA-PSK ");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
ret = os_snprintf(pos, end - pos, "WPA-EAP ");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
#ifdef CONFIG_IEEE80211R
if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_PSK) {
ret = os_snprintf(pos, end - pos, "FT-PSK ");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
ret = os_snprintf(pos, end - pos, "FT-EAP ");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
#ifdef CONFIG_SAE
if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_SAE) {
ret = os_snprintf(pos, end - pos, "FT-SAE ");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -1145,13 +1145,13 @@ static int hostapd_ctrl_iface_get_config(struct hostapd_data *hapd,
#ifdef CONFIG_IEEE80211W
if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
ret = os_snprintf(pos, end - pos, "WPA-PSK-SHA256 ");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
ret = os_snprintf(pos, end - pos, "WPA-EAP-SHA256 ");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -1159,20 +1159,20 @@ static int hostapd_ctrl_iface_get_config(struct hostapd_data *hapd,
#ifdef CONFIG_SAE
if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_SAE) {
ret = os_snprintf(pos, end - pos, "SAE ");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
#endif /* CONFIG_SAE */
if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
ret = os_snprintf(pos, end - pos, "WPA-EAP-SUITE-B ");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
ret = os_snprintf(pos, end - pos, "\n");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -1180,14 +1180,14 @@ static int hostapd_ctrl_iface_get_config(struct hostapd_data *hapd,
if (hapd->conf->wpa) {
ret = os_snprintf(pos, end - pos, "group_cipher=%s\n",
wpa_cipher_txt(hapd->conf->wpa_group));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
if ((hapd->conf->wpa & WPA_PROTO_RSN) && hapd->conf->rsn_pairwise) {
ret = os_snprintf(pos, end - pos, "rsn_pairwise_cipher=");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
@ -1198,14 +1198,14 @@ static int hostapd_ctrl_iface_get_config(struct hostapd_data *hapd,
pos += ret;
ret = os_snprintf(pos, end - pos, "\n");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
if ((hapd->conf->wpa & WPA_PROTO_WPA) && hapd->conf->wpa_pairwise) {
ret = os_snprintf(pos, end - pos, "wpa_pairwise_cipher=");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
@ -1216,7 +1216,7 @@ static int hostapd_ctrl_iface_get_config(struct hostapd_data *hapd,
pos += ret;
ret = os_snprintf(pos, end - pos, "\n");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -1323,7 +1323,7 @@ static int hostapd_ctrl_iface_get(struct hostapd_data *hapd, char *cmd,
if (os_strcmp(cmd, "version") == 0) {
res = os_snprintf(buf, buflen, "%s", VERSION_STR);
if (res < 0 || (unsigned int) res >= buflen)
if (os_snprintf_error(buflen, res))
return -1;
return res;
}

@ -711,7 +711,7 @@ static int gsm_auth_req(char *imsi, char *resp, size_t resp_len)
rend = resp + resp_len;
rpos = resp;
ret = os_snprintf(rpos, rend - rpos, "GSM-AUTH-RESP %s", imsi);
if (ret < 0 || ret >= rend - rpos)
if (os_snprintf_error(rend - rpos, ret))
return -1;
rpos += ret;
@ -737,7 +737,7 @@ static int gsm_auth_req(char *imsi, char *resp, size_t resp_len)
printf("No GSM triplets found for %s\n", imsi);
ret = os_snprintf(rpos, rend - rpos, " FAILURE");
if (ret < 0 || ret >= rend - rpos)
if (os_snprintf_error(rend - rpos, ret))
return -1;
rpos += ret;

@ -596,7 +596,7 @@ static int hostapd_cli_cmd_disassoc_imminent(struct wpa_ctrl *ctrl, int argc,
res = os_snprintf(buf, sizeof(buf), "DISASSOC_IMMINENT %s %s",
argv[0], argv[1]);
if (res < 0 || res >= (int) sizeof(buf))
if (os_snprintf_error(sizeof(buf), res))
return -1;
return wpa_ctrl_command(ctrl, buf);
}
@ -616,7 +616,7 @@ static int hostapd_cli_cmd_ess_disassoc(struct wpa_ctrl *ctrl, int argc,
res = os_snprintf(buf, sizeof(buf), "ESS_DISASSOC %s %s %s",
argv[0], argv[1], argv[2]);
if (res < 0 || res >= (int) sizeof(buf))
if (os_snprintf_error(sizeof(buf), res))
return -1;
return wpa_ctrl_command(ctrl, buf);
}
@ -634,7 +634,7 @@ static int hostapd_cli_cmd_bss_tm_req(struct wpa_ctrl *ctrl, int argc,
}
res = os_snprintf(buf, sizeof(buf), "BSS_TM_REQ %s", argv[0]);
if (res < 0 || res >= (int) sizeof(buf))
if (os_snprintf_error(sizeof(buf), res))
return -1;
total = res;
@ -736,7 +736,7 @@ static int hostapd_cli_cmd_set_qos_map_set(struct wpa_ctrl *ctrl,
}
res = os_snprintf(buf, sizeof(buf), "SET_QOS_MAP_SET %s", argv[0]);
if (res < 0 || res >= (int) sizeof(buf))
if (os_snprintf_error(sizeof(buf), res))
return -1;
return wpa_ctrl_command(ctrl, buf);
}
@ -755,7 +755,7 @@ static int hostapd_cli_cmd_send_qos_map_conf(struct wpa_ctrl *ctrl,
}
res = os_snprintf(buf, sizeof(buf), "SEND_QOS_MAP_CONF %s", argv[0]);
if (res < 0 || res >= (int) sizeof(buf))
if (os_snprintf_error(sizeof(buf), res))
return -1;
return wpa_ctrl_command(ctrl, buf);
}
@ -775,7 +775,7 @@ static int hostapd_cli_cmd_hs20_wnm_notif(struct wpa_ctrl *ctrl, int argc,
res = os_snprintf(buf, sizeof(buf), "HS20_WNM_NOTIF %s %s",
argv[0], argv[1]);
if (res < 0 || res >= (int) sizeof(buf))
if (os_snprintf_error(sizeof(buf), res))
return -1;
return wpa_ctrl_command(ctrl, buf);
}
@ -800,7 +800,7 @@ static int hostapd_cli_cmd_hs20_deauth_req(struct wpa_ctrl *ctrl, int argc,
res = os_snprintf(buf, sizeof(buf),
"HS20_DEAUTH_REQ %s %s %s",
argv[0], argv[1], argv[2]);
if (res < 0 || res >= (int) sizeof(buf))
if (os_snprintf_error(sizeof(buf), res))
return -1;
return wpa_ctrl_command(ctrl, buf);
}

@ -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);

@ -1468,56 +1468,56 @@ int wpa_write_ciphers(char *start, char *end, int ciphers, const char *delim)
if (ciphers & WPA_CIPHER_CCMP_256) {
ret = os_snprintf(pos, end - pos, "%sCCMP-256",
pos == start ? "" : delim);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return -1;
pos += ret;
}
if (ciphers & WPA_CIPHER_GCMP_256) {
ret = os_snprintf(pos, end - pos, "%sGCMP-256",
pos == start ? "" : delim);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return -1;
pos += ret;
}
if (ciphers & WPA_CIPHER_CCMP) {
ret = os_snprintf(pos, end - pos, "%sCCMP",
pos == start ? "" : delim);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return -1;
pos += ret;
}
if (ciphers & WPA_CIPHER_GCMP) {
ret = os_snprintf(pos, end - pos, "%sGCMP",
pos == start ? "" : delim);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return -1;
pos += ret;
}
if (ciphers & WPA_CIPHER_TKIP) {
ret = os_snprintf(pos, end - pos, "%sTKIP",
pos == start ? "" : delim);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return -1;
pos += ret;
}
if (ciphers & WPA_CIPHER_WEP104) {
ret = os_snprintf(pos, end - pos, "%sWEP104",
pos == start ? "" : delim);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return -1;
pos += ret;
}
if (ciphers & WPA_CIPHER_WEP40) {
ret = os_snprintf(pos, end - pos, "%sWEP40",
pos == start ? "" : delim);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return -1;
pos += ret;
}
if (ciphers & WPA_CIPHER_NONE) {
ret = os_snprintf(pos, end - pos, "%sNONE",
pos == start ? "" : delim);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return -1;
pos += ret;
}

@ -111,7 +111,7 @@ try_again:
CONFIG_CTRL_IFACE_CLIENT_DIR "/"
CONFIG_CTRL_IFACE_CLIENT_PREFIX "%d-%d",
(int) getpid(), counter);
if (ret < 0 || (size_t) ret >= sizeof(ctrl->local.sun_path)) {
if (os_snprintf_error(sizeof(ctrl->local.sun_path), ret)) {
close(ctrl->s);
os_free(ctrl);
return NULL;

@ -2868,7 +2868,7 @@ int tls_connection_set_cipher_list(void *tls_ctx, struct tls_connection *conn,
return -1;
}
ret = os_snprintf(pos, end - pos, ":%s", suite);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
break;
pos += ret;

@ -5238,7 +5238,7 @@ static void dump_ifidx(struct wpa_driver_nl80211_data *drv)
if (!drv->if_indices[i])
continue;
res = os_snprintf(pos, end - pos, " %d", drv->if_indices[i]);
if (res < 0 || res >= end - pos)
if (os_snprintf_error(end - pos, res))
break;
pos += res;
}
@ -7120,14 +7120,14 @@ static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen)
bss->added_bridge ? "added_bridge=1\n" : "",
bss->in_deinit ? "in_deinit=1\n" : "",
bss->if_dynamic ? "if_dynamic=1\n" : "");
if (res < 0 || res >= end - pos)
if (os_snprintf_error(end - pos, res))
return pos - buf;
pos += res;
if (bss->wdev_id_set) {
res = os_snprintf(pos, end - pos, "wdev_id=%llu\n",
(unsigned long long) bss->wdev_id);
if (res < 0 || res >= end - pos)
if (os_snprintf_error(end - pos, res))
return pos - buf;
pos += res;
}
@ -7186,7 +7186,7 @@ static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen)
"ignore_next_local_disconnect=1\n" : "",
drv->ignore_next_local_deauth ?
"ignore_next_local_deauth=1\n" : "");
if (res < 0 || res >= end - pos)
if (os_snprintf_error(end - pos, res))
return pos - buf;
pos += res;
@ -7218,7 +7218,7 @@ static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen)
drv->capa.probe_resp_offloads,
drv->capa.max_acl_mac_addrs,
drv->capa.num_multichan_concurrent);
if (res < 0 || res >= end - pos)
if (os_snprintf_error(end - pos, res))
return pos - buf;
pos += res;
}

@ -2373,7 +2373,7 @@ static int wpa_driver_wext_status(void *priv, char *buf, size_t buflen)
drv->ifindex,
drv->ifname,
MAC2STR(addr));
if (res < 0 || res >= end - pos)
if (os_snprintf_error(end - pos, res))
return pos - buf;
pos += res;

@ -2090,7 +2090,7 @@ int eap_sm_get_status(struct eap_sm *sm, char *buf, size_t buflen, int verbose)
len = os_snprintf(buf, buflen,
"EAP state=%s\n",
eap_sm_state_txt(sm->EAP_state));
if (len < 0 || (size_t) len >= buflen)
if (os_snprintf_error(buflen, len))
return 0;
if (sm->selectedMethod != EAP_TYPE_NONE) {
@ -2109,7 +2109,7 @@ int eap_sm_get_status(struct eap_sm *sm, char *buf, size_t buflen, int verbose)
ret = os_snprintf(buf + len, buflen - len,
"selectedMethod=%d (EAP-%s)\n",
sm->selectedMethod, name);
if (ret < 0 || (size_t) ret >= buflen - len)
if (os_snprintf_error(buflen - len, ret))
return len;
len += ret;
@ -2130,7 +2130,7 @@ int eap_sm_get_status(struct eap_sm *sm, char *buf, size_t buflen, int verbose)
eap_sm_method_state_txt(sm->methodState),
eap_sm_decision_txt(sm->decision),
sm->ClientTimeout);
if (ret < 0 || (size_t) ret >= buflen - len)
if (os_snprintf_error(buflen - len, ret))
return len;
len += ret;
}

@ -1666,7 +1666,7 @@ static int eap_fast_get_status(struct eap_sm *sm, void *priv, char *buf,
ret = os_snprintf(buf + len, buflen - len,
"EAP-FAST Phase2 method=%s\n",
data->phase2_method->name);
if (ret < 0 || (size_t) ret >= buflen - len)
if (os_snprintf_error(buflen - len, ret))
return len;
len += ret;
}

@ -504,28 +504,28 @@ static void eap_fast_write(char **buf, char **pos, size_t *buf_len,
end = *buf + *buf_len;
ret = os_snprintf(*pos, end - *pos, "%s=", field);
if (ret < 0 || ret >= end - *pos)
if (os_snprintf_error(end - *pos, ret))
return;
*pos += ret;
*pos += wpa_snprintf_hex(*pos, end - *pos, data, len);
ret = os_snprintf(*pos, end - *pos, "\n");
if (ret < 0 || ret >= end - *pos)
if (os_snprintf_error(end - *pos, ret))
return;
*pos += ret;
if (txt) {
ret = os_snprintf(*pos, end - *pos, "%s-txt=", field);
if (ret < 0 || ret >= end - *pos)
if (os_snprintf_error(end - *pos, ret))
return;
*pos += ret;
for (i = 0; i < len; i++) {
ret = os_snprintf(*pos, end - *pos, "%c", data[i]);
if (ret < 0 || ret >= end - *pos)
if (os_snprintf_error(end - *pos, ret))
return;
*pos += ret;
}
ret = os_snprintf(*pos, end - *pos, "\n");
if (ret < 0 || ret >= end - *pos)
if (os_snprintf_error(end - *pos, ret))
return;
*pos += ret;
}
@ -578,7 +578,7 @@ static int eap_fast_add_pac_data(struct eap_fast_pac *pac, char **buf,
ret = os_snprintf(*pos, *buf + *buf_len - *pos,
"START\nPAC-Type=%d\n", pac->pac_type);
if (ret < 0 || ret >= *buf + *buf_len - *pos)
if (os_snprintf_error(*buf + *buf_len - *pos, ret))
return -1;
*pos += ret;
@ -600,7 +600,7 @@ static int eap_fast_add_pac_data(struct eap_fast_pac *pac, char **buf,
return -1;
}
ret = os_snprintf(*pos, *buf + *buf_len - *pos, "END\n");
if (ret < 0 || ret >= *buf + *buf_len - *pos)
if (os_snprintf_error(*buf + *buf_len - *pos, ret))
return -1;
*pos += ret;
@ -632,7 +632,7 @@ int eap_fast_save_pac(struct eap_sm *sm, struct eap_fast_pac *pac_root,
return -1;
ret = os_snprintf(pos, buf + buf_len - pos, "%s\n", pac_file_hdr);
if (ret < 0 || ret >= buf + buf_len - pos) {
if (os_snprintf_error(buf + buf_len - pos, ret)) {
os_free(buf);
return -1;
}

@ -103,7 +103,7 @@ size_t eap_get_names(char *buf, size_t buflen)
for (m = eap_methods; m; m = m->next) {
ret = os_snprintf(pos, end - pos, "%s%s",
m == eap_methods ? "" : " ", m->name);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
break;
pos += ret;
}

@ -1156,7 +1156,7 @@ static int eap_peap_get_status(struct eap_sm *sm, void *priv, char *buf,
"EAP-PEAPv%d Phase2 method=%s\n",
data->peap_version,
data->phase2_method->name);
if (ret < 0 || (size_t) ret >= buflen - len)
if (os_snprintf_error(buflen - len, ret))
return len;
len += ret;
}

@ -793,7 +793,7 @@ int eap_peer_tls_status(struct eap_sm *sm, struct eap_ssl_data *data,
{
ret = os_snprintf(buf + len, buflen - len,
"EAP TLS cipher=%s\n", name);
if (ret < 0 || (size_t) ret >= buflen - len)
if (os_snprintf_error(buflen - len, ret))
return len;
len += ret;
}

@ -1571,7 +1571,7 @@ static int eap_ttls_get_status(struct eap_sm *sm, void *priv, char *buf,
ret = os_snprintf(buf + len, buflen - len,
"EAP-TTLSv%d Phase2 method=",
data->ttls_version);
if (ret < 0 || (size_t) ret >= buflen - len)
if (os_snprintf_error(buflen - len, ret))
return len;
len += ret;
switch (data->phase2_type) {

@ -927,7 +927,7 @@ int eap_sim_db_get_gsm_triplets(struct eap_sim_db_data *data,
os_memcpy(msg + len, imsi, imsi_len);
len += imsi_len;
ret = os_snprintf(msg + len, sizeof(msg) - len, " %d", max_chal);
if (ret < 0 || (size_t) ret >= sizeof(msg) - len)
if (os_snprintf_error(sizeof(msg) - len, ret))
return EAP_SIM_DB_FAILURE;
len += ret;
@ -1455,13 +1455,13 @@ int eap_sim_db_resynchronize(struct eap_sim_db_data *data,
len += imsi_len;
ret = os_snprintf(msg + len, sizeof(msg) - len, " ");
if (ret < 0 || (size_t) ret >= sizeof(msg) - len)
if (os_snprintf_error(sizeof(msg) - len, ret))
return -1;
len += ret;
len += wpa_snprintf_hex(msg + len, sizeof(msg) - len,
auts, EAP_AKA_AUTS_LEN);
ret = os_snprintf(msg + len, sizeof(msg) - len, " ");
if (ret < 0 || (size_t) ret >= sizeof(msg) - len)
if (os_snprintf_error(sizeof(msg) - len, ret))
return -1;
len += ret;
len += wpa_snprintf_hex(msg + len, sizeof(msg) - len,

@ -130,7 +130,7 @@ int eapol_auth_dump_state(struct eapol_state_machine *sm, char *buf,
ret = os_snprintf(pos, end - pos, "aWhile=%d\nquietWhile=%d\n"
"reAuthWhen=%d\n",
sm->aWhile, sm->quietWhile, sm->reAuthWhen);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
@ -173,7 +173,7 @@ int eapol_auth_dump_state(struct eapol_state_machine *sm, char *buf,
_SB(sm->eap_if->portEnabled),
_SB(sm->portValid),
_SB(sm->reAuthenticate));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
@ -215,7 +215,7 @@ int eapol_auth_dump_state(struct eapol_state_machine *sm, char *buf,
sm->authAuthReauthsWhileAuthenticated,
sm->authAuthEapStartsWhileAuthenticated,
sm->authAuthEapLogoffWhileAuthenticated);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
@ -240,7 +240,7 @@ int eapol_auth_dump_state(struct eapol_state_machine *sm, char *buf,
sm->backendOtherRequestsToSupplicant,
sm->backendAuthSuccesses,
sm->backendAuthFails);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
@ -251,14 +251,14 @@ int eapol_auth_dump_state(struct eapol_state_machine *sm, char *buf,
reauth_timer_state_txt(sm->reauth_timer_state),
sm->reAuthPeriod,
_SB(sm->reAuthEnabled));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
ret = os_snprintf(pos, end - pos,
"auth_key_tx_state=%s\n",
auth_key_tx_state_txt(sm->auth_key_tx_state));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
@ -267,7 +267,7 @@ int eapol_auth_dump_state(struct eapol_state_machine *sm, char *buf,
"rxKey=%s\n",
key_rx_state_txt(sm->key_rx_state),
_SB(sm->rxKey));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
@ -280,7 +280,7 @@ int eapol_auth_dump_state(struct eapol_state_machine *sm, char *buf,
ctrl_dir_txt(sm->adminControlledDirections),
ctrl_dir_txt(sm->operControlledDirections),
_SB(sm->operEdge));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
#undef _SB

@ -1108,7 +1108,7 @@ int eapol_sm_get_status(struct eapol_sm *sm, char *buf, size_t buflen,
"suppPortStatus=%s\n",
eapol_supp_pae_state(sm->SUPP_PAE_state),
eapol_port_status(sm->suppPortStatus));
if (len < 0 || (size_t) len >= buflen)
if (os_snprintf_error(buflen, len))
return 0;
if (verbose) {
@ -1125,7 +1125,7 @@ int eapol_sm_get_status(struct eapol_sm *sm, char *buf, size_t buflen,
sm->maxStart,
eapol_port_control(sm->portControl),
eapol_supp_be_state(sm->SUPP_BE_state));
if (ret < 0 || (size_t) ret >= buflen - len)
if (os_snprintf_error(buflen - len, ret))
return len;
len += ret;
}
@ -1179,7 +1179,7 @@ int eapol_sm_get_mib(struct eapol_sm *sm, char *buf, size_t buflen)
"Authorized" : "Unauthorized",
sm->SUPP_BE_state);
if (ret < 0 || (size_t) ret >= buflen)
if (os_snprintf_error(buflen, ret))
return 0;
len = ret;
@ -1207,7 +1207,7 @@ int eapol_sm_get_mib(struct eapol_sm *sm, char *buf, size_t buflen)
sm->dot1xSuppLastEapolFrameVersion,
MAC2STR(sm->dot1xSuppLastEapolFrameSource));
if (ret < 0 || (size_t) ret >= buflen - len)
if (os_snprintf_error(buflen - len, ret))
return len;
len += ret;

@ -3750,7 +3750,7 @@ int p2p_get_peer_info_txt(const struct p2p_peer_info *info,
"[PD_FOR_JOIN]" : "",
dev->status,
dev->invitation_reqs);
if (res < 0 || res >= end - pos)
if (os_snprintf_error(end - pos, res))
return pos - buf;
pos += res;
@ -3760,7 +3760,7 @@ int p2p_get_peer_info_txt(const struct p2p_peer_info *info,
"ext_listen_interval=%u\n",
dev->ext_listen_period,
dev->ext_listen_interval);
if (res < 0 || res >= end - pos)
if (os_snprintf_error(end - pos, res))
return pos - buf;
pos += res;
}
@ -3770,7 +3770,7 @@ int p2p_get_peer_info_txt(const struct p2p_peer_info *info,
"oper_ssid=%s\n",
wpa_ssid_txt(dev->oper_ssid,
dev->oper_ssid_len));
if (res < 0 || res >= end - pos)
if (os_snprintf_error(end - pos, res))
return pos - buf;
pos += res;
}
@ -3778,7 +3778,7 @@ int p2p_get_peer_info_txt(const struct p2p_peer_info *info,
#ifdef CONFIG_WIFI_DISPLAY
if (dev->info.wfd_subelems) {
res = os_snprintf(pos, end - pos, "wfd_subelems=");
if (res < 0 || res >= end - pos)
if (os_snprintf_error(end - pos, res))
return pos - buf;
pos += res;
@ -3787,7 +3787,7 @@ int p2p_get_peer_info_txt(const struct p2p_peer_info *info,
wpabuf_len(dev->info.wfd_subelems));
res = os_snprintf(pos, end - pos, "\n");
if (res < 0 || res >= end - pos)
if (os_snprintf_error(end - pos, res))
return pos - buf;
pos += res;
}

@ -607,7 +607,7 @@ static int p2p_group_info_text(const u8 *gi, size_t gi_len, char *buf,
"dev=" MACSTR " iface=" MACSTR,
MAC2STR(cli->p2p_device_addr),
MAC2STR(cli->p2p_interface_addr));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
@ -618,7 +618,7 @@ static int p2p_group_info_text(const u8 *gi, size_t gi_len, char *buf,
wps_dev_type_bin2str(cli->pri_dev_type,
devtype,
sizeof(devtype)));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
@ -627,7 +627,7 @@ static int p2p_group_info_text(const u8 *gi, size_t gi_len, char *buf,
wps_dev_type_bin2str(
&cli->sec_dev_types[s * 8],
devtype, sizeof(devtype)));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -642,7 +642,7 @@ static int p2p_group_info_text(const u8 *gi, size_t gi_len, char *buf,
}
ret = os_snprintf(pos, end - pos, " dev_name='%s'\n", name);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -676,7 +676,7 @@ int p2p_attr_text(struct wpabuf *data, char *buf, char *end)
"p2p_dev_capab=0x%x\n"
"p2p_group_capab=0x%x\n",
msg.capability[0], msg.capability[1]);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -688,14 +688,14 @@ int p2p_attr_text(struct wpabuf *data, char *buf, char *end)
wps_dev_type_bin2str(msg.pri_dev_type,
devtype,
sizeof(devtype)));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
ret = os_snprintf(pos, end - pos, "p2p_device_name=%s\n",
msg.device_name);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
@ -703,14 +703,14 @@ int p2p_attr_text(struct wpabuf *data, char *buf, char *end)
ret = os_snprintf(pos, end - pos, "p2p_device_addr=" MACSTR
"\n",
MAC2STR(msg.p2p_device_addr));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
ret = os_snprintf(pos, end - pos, "p2p_config_methods=0x%x\n",
msg.config_methods);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;

@ -390,7 +390,7 @@ void p2p_channels_dump(struct p2p_data *p2p, const char *title,
const struct p2p_reg_class *c;
c = &chan->reg_class[i];
ret = os_snprintf(pos, end - pos, " %u:", c->reg_class);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
break;
pos += ret;
@ -398,7 +398,7 @@ void p2p_channels_dump(struct p2p_data *p2p, const char *title,
ret = os_snprintf(pos, end - pos, "%s%u",
j == 0 ? "" : ",",
c->channel[j]);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
break;
pos += ret;
}

@ -1900,7 +1900,7 @@ int radius_server_get_mib(struct radius_server_data *data, char *buf,
"radiusAuthServResetTime=0\n"
"radiusAuthServConfigReset=4\n",
uptime);
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
*pos = '\0';
return pos - buf;
}
@ -1939,7 +1939,7 @@ int radius_server_get_mib(struct radius_server_data *data, char *buf,
data->counters.malformed_acct_requests,
data->counters.acct_bad_authenticators,
data->counters.unknown_acct_types);
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
*pos = '\0';
return pos - buf;
}
@ -1997,7 +1997,7 @@ int radius_server_get_mib(struct radius_server_data *data, char *buf,
cli->counters.malformed_acct_requests,
cli->counters.acct_bad_authenticators,
cli->counters.unknown_acct_types);
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
*pos = '\0';
return pos - buf;
}

@ -482,7 +482,7 @@ int pmksa_cache_list(struct rsn_pmksa_cache *pmksa, char *buf, size_t len)
ret = os_snprintf(pos, buf + len - pos,
"Index / AA / PMKID / expiration (in seconds) / "
"opportunistic\n");
if (ret < 0 || ret >= buf + len - pos)
if (os_snprintf_error(buf + len - pos, ret))
return pos - buf;
pos += ret;
i = 0;
@ -491,7 +491,7 @@ int pmksa_cache_list(struct rsn_pmksa_cache *pmksa, char *buf, size_t len)
i++;
ret = os_snprintf(pos, buf + len - pos, "%d " MACSTR " ",
i, MAC2STR(entry->aa));
if (ret < 0 || ret >= buf + len - pos)
if (os_snprintf_error(buf + len - pos, ret))
return pos - buf;
pos += ret;
pos += wpa_snprintf_hex(pos, buf + len - pos, entry->pmkid,
@ -499,7 +499,7 @@ int pmksa_cache_list(struct rsn_pmksa_cache *pmksa, char *buf, size_t len)
ret = os_snprintf(pos, buf + len - pos, " %d %d\n",
(int) (entry->expiration - now.sec),
entry->opportunistic);
if (ret < 0 || ret >= buf + len - pos)
if (os_snprintf_error(buf + len - pos, ret))
return pos - buf;
pos += ret;
entry = entry->next;

@ -501,7 +501,7 @@ int rsn_preauth_get_status(struct wpa_sm *sm, char *buf, size_t buflen,
if (sm->preauth_eapol) {
ret = os_snprintf(pos, end - pos, "Pre-authentication "
"EAPOL state machines:\n");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
res = eapol_sm_get_status(sm->preauth_eapol,

@ -2015,7 +2015,7 @@ int wpa_sm_get_mib(struct wpa_sm *sm, char *buf, size_t buflen)
sm->dot11RSNAConfigPMKLifetime,
sm->dot11RSNAConfigPMKReauthThreshold,
sm->dot11RSNAConfigSATimeout);
if (ret < 0 || (size_t) ret >= buflen)
if (os_snprintf_error(buflen, ret))
return 0;
len = ret;
@ -2484,7 +2484,7 @@ int wpa_sm_get_status(struct wpa_sm *sm, char *buf, size_t buflen,
wpa_cipher_txt(sm->pairwise_cipher),
wpa_cipher_txt(sm->group_cipher),
wpa_key_mgmt_txt(sm->key_mgmt, sm->proto));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
@ -2497,7 +2497,7 @@ int wpa_sm_get_status(struct wpa_sm *sm, char *buf, size_t buflen,
ret = os_snprintf(pos, end - pos, "pmf=%d\n",
(rsn.capabilities &
WPA_CAPABILITY_MFPR) ? 2 : 1);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}

@ -166,7 +166,7 @@ void asn1_oid_to_str(const struct asn1_oid *oid, char *buf, size_t len)
ret = os_snprintf(pos, buf + len - pos,
"%s%lu",
i == 0 ? "" : ".", oid->oid[i]);
if (ret < 0 || ret >= buf + len - pos)
if (os_snprintf_error(buf + len - pos, ret))
break;
pos += ret;
}

@ -512,7 +512,7 @@ void x509_name_string(struct x509_name *name, char *buf, size_t len)
ret = os_snprintf(pos, end - pos, "%s=%s, ",
x509_name_attr_str(name->attr[i].type),
name->attr[i].value);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
goto done;
pos += ret;
}
@ -527,7 +527,7 @@ void x509_name_string(struct x509_name *name, char *buf, size_t len)
if (name->email) {
ret = os_snprintf(pos, end - pos, "/emailAddress=%s",
name->email);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
goto done;
pos += ret;
}

@ -224,7 +224,7 @@ static inline int _wpa_snprintf_hex(char *buf, size_t buf_size, const u8 *data,
for (i = 0; i < len; i++) {
ret = os_snprintf(pos, end - pos, uppercase ? "%02X" : "%02x",
data[i]);
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
end[-1] = '\0';
return pos - buf;
}

@ -55,7 +55,7 @@ int uuid_bin2str(const u8 *bin, char *str, size_t max_len)
bin[4], bin[5], bin[6], bin[7],
bin[8], bin[9], bin[10], bin[11],
bin[12], bin[13], bin[14], bin[15]);
if (len < 0 || (size_t) len >= max_len)
if (os_snprintf_error(max_len, len))
return -1;
return 0;
}

@ -619,7 +619,7 @@ void wpa_msg(void *ctx, int level, const char *fmt, ...)
if (ifname) {
int res = os_snprintf(prefix, sizeof(prefix), "%s: ",
ifname);
if (res < 0 || res >= (int) sizeof(prefix))
if (os_snprintf_error(sizeof(prefix), res))
prefix[0] = '\0';
}
}

@ -560,7 +560,7 @@ int wps_attr_text(struct wpabuf *data, char *buf, char *end)
"wps_state=configured\n");
else
ret = 0;
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -568,7 +568,7 @@ int wps_attr_text(struct wpabuf *data, char *buf, char *end)
if (attr.ap_setup_locked && *attr.ap_setup_locked) {
ret = os_snprintf(pos, end - pos,
"wps_ap_setup_locked=1\n");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -576,7 +576,7 @@ int wps_attr_text(struct wpabuf *data, char *buf, char *end)
if (attr.selected_registrar && *attr.selected_registrar) {
ret = os_snprintf(pos, end - pos,
"wps_selected_registrar=1\n");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -585,7 +585,7 @@ int wps_attr_text(struct wpabuf *data, char *buf, char *end)
ret = os_snprintf(pos, end - pos,
"wps_device_password_id=%u\n",
WPA_GET_BE16(attr.dev_password_id));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -595,7 +595,7 @@ int wps_attr_text(struct wpabuf *data, char *buf, char *end)
"wps_selected_registrar_config_methods="
"0x%04x\n",
WPA_GET_BE16(attr.sel_reg_config_methods));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -607,7 +607,7 @@ int wps_attr_text(struct wpabuf *data, char *buf, char *end)
wps_dev_type_bin2str(attr.primary_dev_type,
devtype,
sizeof(devtype)));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -626,7 +626,7 @@ int wps_attr_text(struct wpabuf *data, char *buf, char *end)
str[i] = '\0';
ret = os_snprintf(pos, end - pos, "wps_device_name=%s\n", str);
os_free(str);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -635,7 +635,7 @@ int wps_attr_text(struct wpabuf *data, char *buf, char *end)
ret = os_snprintf(pos, end - pos,
"wps_config_methods=0x%04x\n",
WPA_GET_BE16(attr.config_methods));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}

@ -489,7 +489,7 @@ char * wps_dev_type_bin2str(const u8 dev_type[WPS_DEV_TYPE_LEN], char *buf,
ret = os_snprintf(buf, buf_len, "%u-%08X-%u",
WPA_GET_BE16(dev_type), WPA_GET_BE32(&dev_type[2]),
WPA_GET_BE16(&dev_type[6]));
if (ret < 0 || (unsigned int) ret >= buf_len)
if (os_snprintf_error(buf_len, ret))
return NULL;
return buf;

@ -3495,7 +3495,7 @@ int wps_registrar_get_info(struct wps_registrar *reg, const u8 *addr,
d->dev.model_name ? d->dev.model_name : "",
d->dev.model_number ? d->dev.model_number : "",
d->dev.serial_number ? d->dev.serial_number : "");
if (ret < 0 || (size_t) ret >= buflen - len)
if (os_snprintf_error(buflen - len, ret))
return len;
len += ret;

@ -904,7 +904,7 @@ int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
return -1;
hapd = wpa_s->ap_iface->bss[0];
ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
if (ret < 0 || ret >= (int) sizeof(pin_txt))
if (os_snprintf_error(sizeof(pin_txt), ret))
return -1;
os_free(hapd->conf->ap_pin);
hapd->conf->ap_pin = os_strdup(pin_txt);
@ -1058,7 +1058,7 @@ int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
wpa_cipher_txt(conf->wpa_group),
wpa_key_mgmt_txt(conf->wpa_key_mgmt,
conf->wpa));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
return pos - buf;

@ -294,7 +294,7 @@ static void bgscan_learn_timeout(void *eloop_ctx, void *timeout_ctx)
int ret;
ret = os_snprintf(pos, msg + sizeof(msg) - pos, " %d",
freqs[i]);
if (ret < 0 || ret >= msg + sizeof(msg) - pos)
if (os_snprintf_error(msg + sizeof(msg) - pos, ret))
break;
pos += ret;
}

@ -225,7 +225,7 @@ static char * wpa_config_write_int(const struct parse_data *data,
if (value == NULL)
return NULL;
res = os_snprintf(value, 20, "%d", *src);
if (res < 0 || res >= 20) {
if (os_snprintf_error(20, res)) {
os_free(value);
return NULL;
}
@ -270,7 +270,7 @@ static char * wpa_config_write_bssid(const struct parse_data *data,
if (value == NULL)
return NULL;
res = os_snprintf(value, 20, MACSTR, MAC2STR(ssid->bssid));
if (res < 0 || res >= 20) {
if (os_snprintf_error(20, res)) {
os_free(value);
return NULL;
}
@ -446,7 +446,7 @@ static char * wpa_config_write_proto(const struct parse_data *data,
if (ssid->proto & WPA_PROTO_WPA) {
ret = os_snprintf(pos, end - pos, "%sWPA",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return buf;
pos += ret;
}
@ -454,7 +454,7 @@ static char * wpa_config_write_proto(const struct parse_data *data,
if (ssid->proto & WPA_PROTO_RSN) {
ret = os_snprintf(pos, end - pos, "%sRSN",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return buf;
pos += ret;
}
@ -462,7 +462,7 @@ static char * wpa_config_write_proto(const struct parse_data *data,
if (ssid->proto & WPA_PROTO_OSEN) {
ret = os_snprintf(pos, end - pos, "%sOSEN",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return buf;
pos += ret;
}
@ -576,7 +576,7 @@ static char * wpa_config_write_key_mgmt(const struct parse_data *data,
if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) {
ret = os_snprintf(pos, end - pos, "%sWPA-PSK",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
end[-1] = '\0';
return buf;
}
@ -586,7 +586,7 @@ static char * wpa_config_write_key_mgmt(const struct parse_data *data,
if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
ret = os_snprintf(pos, end - pos, "%sWPA-EAP",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
end[-1] = '\0';
return buf;
}
@ -596,7 +596,7 @@ static char * wpa_config_write_key_mgmt(const struct parse_data *data,
if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
ret = os_snprintf(pos, end - pos, "%sIEEE8021X",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
end[-1] = '\0';
return buf;
}
@ -606,7 +606,7 @@ static char * wpa_config_write_key_mgmt(const struct parse_data *data,
if (ssid->key_mgmt & WPA_KEY_MGMT_NONE) {
ret = os_snprintf(pos, end - pos, "%sNONE",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
end[-1] = '\0';
return buf;
}
@ -616,7 +616,7 @@ static char * wpa_config_write_key_mgmt(const struct parse_data *data,
if (ssid->key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
ret = os_snprintf(pos, end - pos, "%sWPA-NONE",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
end[-1] = '\0';
return buf;
}
@ -627,7 +627,7 @@ static char * wpa_config_write_key_mgmt(const struct parse_data *data,
if (ssid->key_mgmt & WPA_KEY_MGMT_FT_PSK) {
ret = os_snprintf(pos, end - pos, "%sFT-PSK",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
end[-1] = '\0';
return buf;
}
@ -637,7 +637,7 @@ static char * wpa_config_write_key_mgmt(const struct parse_data *data,
if (ssid->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
ret = os_snprintf(pos, end - pos, "%sFT-EAP",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
end[-1] = '\0';
return buf;
}
@ -649,7 +649,7 @@ static char * wpa_config_write_key_mgmt(const struct parse_data *data,
if (ssid->key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
ret = os_snprintf(pos, end - pos, "%sWPA-PSK-SHA256",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
end[-1] = '\0';
return buf;
}
@ -659,7 +659,7 @@ static char * wpa_config_write_key_mgmt(const struct parse_data *data,
if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
ret = os_snprintf(pos, end - pos, "%sWPA-EAP-SHA256",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
end[-1] = '\0';
return buf;
}
@ -671,7 +671,7 @@ static char * wpa_config_write_key_mgmt(const struct parse_data *data,
if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
ret = os_snprintf(pos, end - pos, "%sWPS",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
end[-1] = '\0';
return buf;
}
@ -683,7 +683,7 @@ static char * wpa_config_write_key_mgmt(const struct parse_data *data,
if (ssid->key_mgmt & WPA_KEY_MGMT_SAE) {
ret = os_snprintf(pos, end - pos, "%sSAE",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
end[-1] = '\0';
return buf;
}
@ -693,7 +693,7 @@ static char * wpa_config_write_key_mgmt(const struct parse_data *data,
if (ssid->key_mgmt & WPA_KEY_MGMT_FT_SAE) {
ret = os_snprintf(pos, end - pos, "%sFT-SAE",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
end[-1] = '\0';
return buf;
}
@ -705,7 +705,7 @@ static char * wpa_config_write_key_mgmt(const struct parse_data *data,
if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN) {
ret = os_snprintf(pos, end - pos, "%sOSEN",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
end[-1] = '\0';
return buf;
}
@ -716,7 +716,7 @@ static char * wpa_config_write_key_mgmt(const struct parse_data *data,
if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
ret = os_snprintf(pos, end - pos, "%sWPA-EAP-SUITE-B",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
end[-1] = '\0';
return buf;
}
@ -892,7 +892,7 @@ static char * wpa_config_write_auth_alg(const struct parse_data *data,
if (ssid->auth_alg & WPA_AUTH_ALG_OPEN) {
ret = os_snprintf(pos, end - pos, "%sOPEN",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
end[-1] = '\0';
return buf;
}
@ -902,7 +902,7 @@ static char * wpa_config_write_auth_alg(const struct parse_data *data,
if (ssid->auth_alg & WPA_AUTH_ALG_SHARED) {
ret = os_snprintf(pos, end - pos, "%sSHARED",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
end[-1] = '\0';
return buf;
}
@ -912,7 +912,7 @@ static char * wpa_config_write_auth_alg(const struct parse_data *data,
if (ssid->auth_alg & WPA_AUTH_ALG_LEAP) {
ret = os_snprintf(pos, end - pos, "%sLEAP",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
end[-1] = '\0';
return buf;
}
@ -1033,7 +1033,7 @@ static char * wpa_config_write_freqs(const struct parse_data *data,
for (i = 0; freqs[i]; i++) {
ret = os_snprintf(pos, end - pos, "%s%u",
i == 0 ? "" : " ", freqs[i]);
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
end[-1] = '\0';
return buf;
}
@ -1156,7 +1156,7 @@ static char * wpa_config_write_eap(const struct parse_data *data,
if (name) {
ret = os_snprintf(pos, end - pos, "%s%s",
pos == buf ? "" : " ", name);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
break;
pos += ret;
}
@ -1433,7 +1433,7 @@ static char * wpa_config_write_go_p2p_dev_addr(const struct parse_data *data,
if (value == NULL)
return NULL;
res = os_snprintf(value, 20, MACSTR, MAC2STR(ssid->go_p2p_dev_addr));
if (res < 0 || res >= 20) {
if (os_snprintf_error(20, res)) {
os_free(value);
return NULL;
}
@ -1518,7 +1518,7 @@ static char * wpa_config_write_p2p_client_list(const struct parse_data *data,
res = os_snprintf(pos, end - pos, MACSTR " ",
MAC2STR(ssid->p2p_client_list +
(i - 1) * ETH_ALEN));
if (res < 0 || res >= end - pos) {
if (os_snprintf_error(end - pos, res)) {
os_free(value);
return NULL;
}
@ -3071,7 +3071,7 @@ char * wpa_config_get_cred_no_key(struct wpa_cred *cred, const char *var)
ret = os_snprintf(pos, end - pos, "%s%u",
i > 0 ? "\n" : "",
cred->req_conn_capab_proto[i]);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return buf;
pos += ret;
@ -3083,7 +3083,7 @@ char * wpa_config_get_cred_no_key(struct wpa_cred *cred, const char *var)
"%s%d",
j > 0 ? "," : ":",
ports[j]);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return buf;
pos += ret;
}
@ -3152,7 +3152,7 @@ char * wpa_config_get_cred_no_key(struct wpa_cred *cred, const char *var)
for (i = 0; i < cred->num_domain; i++) {
ret = os_snprintf(pos, end - pos, "%s%s",
i > 0 ? "\n" : "", cred->domain[i]);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return buf;
pos += ret;
}
@ -3217,7 +3217,7 @@ char * wpa_config_get_cred_no_key(struct wpa_cred *cred, const char *var)
ret = os_snprintf(pos, end - pos, "%s%s",
i > 0 ? "\n" : "",
wpa_ssid_txt(e->ssid, e->ssid_len));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return buf;
pos += ret;
}
@ -3247,7 +3247,7 @@ char * wpa_config_get_cred_no_key(struct wpa_cred *cred, const char *var)
i > 0 ? "\n" : "",
p->fqdn, p->exact_match, p->priority,
p->country);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return buf;
pos += ret;
}

@ -608,7 +608,7 @@ static void write_wep_key(FILE *f, int idx, struct wpa_ssid *ssid)
int res;
res = os_snprintf(field, sizeof(field), "wep_key%d", idx);
if (res < 0 || (size_t) res >= sizeof(field))
if (os_snprintf_error(sizeof(field), res))
return;
value = wpa_config_get(ssid, field);
if (value) {

@ -475,7 +475,7 @@ static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
else
enabled = wpa_s->global->wifi_display;
res = os_snprintf(buf, buflen, "%d", enabled);
if (res < 0 || (unsigned int) res >= buflen)
if (os_snprintf_error(buflen, res))
return -1;
return res;
#endif /* CONFIG_WIFI_DISPLAY */
@ -813,7 +813,7 @@ static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
if (ret < 0)
return -1;
ret = os_snprintf(buf, buflen, "%s", pin);
if (ret < 0 || (size_t) ret >= buflen)
if (os_snprintf_error(buflen, ret))
return -1;
return ret;
}
@ -825,7 +825,7 @@ static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
done:
/* Return the generated PIN */
ret = os_snprintf(buf, buflen, "%08d", ret);
if (ret < 0 || (size_t) ret >= buflen)
if (os_snprintf_error(buflen, ret))
return -1;
return ret;
}
@ -862,14 +862,14 @@ static int wpa_supplicant_ctrl_iface_wps_check_pin(
if (!wps_pin_valid(pin_val)) {
wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
if (ret < 0 || (size_t) ret >= buflen)
if (os_snprintf_error(buflen, ret))
return -1;
return ret;
}
}
ret = os_snprintf(buf, buflen, "%s", pin);
if (ret < 0 || (size_t) ret >= buflen)
if (os_snprintf_error(buflen, ret))
return -1;
return ret;
@ -1603,12 +1603,12 @@ static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
struct wpa_ssid *ssid = wpa_s->current_ssid;
ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
MAC2STR(wpa_s->bssid));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
ret = os_snprintf(pos, end - pos, "freq=%u\n",
wpa_s->assoc_freq);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
if (ssid) {
@ -1626,7 +1626,7 @@ static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
wpa_ssid_txt(_ssid, ssid_len),
ssid->id);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
@ -1637,7 +1637,7 @@ static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
ret = os_snprintf(pos, end - pos,
"passphrase=%s\n",
ssid->passphrase);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -1645,7 +1645,7 @@ static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
ret = os_snprintf(pos, end - pos,
"id_str=%s\n",
ssid->id_str);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -1698,21 +1698,21 @@ static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
wpa_s->sme.sae.state == SAE_ACCEPTED) {
ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
wpa_s->sme.sae.group);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
#endif /* CONFIG_SAE */
ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
wpa_supplicant_state_txt(wpa_s->wpa_state));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
if (wpa_s->l2 &&
l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -1721,7 +1721,7 @@ static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
if (wpa_s->global->p2p) {
ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
"\n", MAC2STR(wpa_s->global->p2p_dev_addr));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -1729,7 +1729,7 @@ static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
MAC2STR(wpa_s->own_addr));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
@ -1745,7 +1745,7 @@ static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
release = rel_num + 1;
}
ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -1764,7 +1764,7 @@ static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
ret = os_snprintf(pos, end - pos,
"provisioning_sp=%s\n",
cred->provisioning_sp);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -1787,7 +1787,7 @@ static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
}
ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
cred->domain[i]);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
@ -1807,7 +1807,7 @@ static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
type = "unknown";
ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
@ -1833,7 +1833,7 @@ static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
char uuid_str[100];
uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -1921,7 +1921,7 @@ static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
while (e) {
ret = os_snprintf(pos, end - pos, MACSTR "\n",
MAC2STR(e->bssid));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
e = e->next;
@ -2011,7 +2011,7 @@ static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
"Timestamp: %d\n",
debug_level_str(wpa_debug_level),
wpa_debug_timestamp);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
ret = 0;
return ret;
@ -2054,7 +2054,7 @@ static int wpa_supplicant_ctrl_iface_list_networks(
end = buf + buflen;
ret = os_snprintf(pos, end - pos,
"network id / ssid / bssid / flags\n");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
@ -2075,7 +2075,7 @@ static int wpa_supplicant_ctrl_iface_list_networks(
ret = os_snprintf(pos, end - pos, "%d\t%s",
ssid->id,
wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return prev - buf;
pos += ret;
if (ssid->bssid_set) {
@ -2084,7 +2084,7 @@ static int wpa_supplicant_ctrl_iface_list_networks(
} else {
ret = os_snprintf(pos, end - pos, "\tany");
}
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return prev - buf;
pos += ret;
ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
@ -2095,11 +2095,11 @@ static int wpa_supplicant_ctrl_iface_list_networks(
"[TEMP-DISABLED]" : "",
ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
"");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return prev - buf;
pos += ret;
ret = os_snprintf(pos, end - pos, "\n");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return prev - buf;
pos += ret;
@ -2114,7 +2114,7 @@ static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
{
int ret;
ret = os_snprintf(pos, end - pos, "-");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos;
pos += ret;
ret = wpa_write_ciphers(pos, end, cipher, "+");
@ -2133,13 +2133,13 @@ static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
int ret;
ret = os_snprintf(pos, end - pos, "[%s-", proto);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos;
pos += ret;
if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
ret = os_snprintf(pos, end - pos, "?]");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos;
pos += ret;
return pos;
@ -2149,28 +2149,28 @@ static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
ret = os_snprintf(pos, end - pos, "%sEAP",
pos == start ? "" : "+");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos;
pos += ret;
}
if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
ret = os_snprintf(pos, end - pos, "%sPSK",
pos == start ? "" : "+");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos;
pos += ret;
}
if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
ret = os_snprintf(pos, end - pos, "%sNone",
pos == start ? "" : "+");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos;
pos += ret;
}
if (data.key_mgmt & WPA_KEY_MGMT_SAE) {
ret = os_snprintf(pos, end - pos, "%sSAE",
pos == start ? "" : "+");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos;
pos += ret;
}
@ -2178,21 +2178,21 @@ static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
ret = os_snprintf(pos, end - pos, "%sFT/EAP",
pos == start ? "" : "+");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos;
pos += ret;
}
if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
ret = os_snprintf(pos, end - pos, "%sFT/PSK",
pos == start ? "" : "+");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos;
pos += ret;
}
if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) {
ret = os_snprintf(pos, end - pos, "%sFT/SAE",
pos == start ? "" : "+");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos;
pos += ret;
}
@ -2201,14 +2201,14 @@ static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
pos == start ? "" : "+");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos;
pos += ret;
}
if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
pos == start ? "" : "+");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos;
pos += ret;
}
@ -2217,7 +2217,7 @@ static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B",
pos == start ? "" : "+");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos;
pos += ret;
}
@ -2226,13 +2226,13 @@ static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
ret = os_snprintf(pos, end - pos, "-preauth");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos;
pos += ret;
}
ret = os_snprintf(pos, end - pos, "]");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos;
pos += ret;
@ -2305,7 +2305,7 @@ static int wpa_supplicant_ctrl_iface_scan_result(
ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
MAC2STR(bss->bssid), bss->freq, bss->level);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return -1;
pos += ret;
ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
@ -2319,20 +2319,20 @@ static int wpa_supplicant_ctrl_iface_scan_result(
pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
ret = os_snprintf(pos, end - pos, "[WEP]");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return -1;
pos += ret;
}
if (mesh) {
ret = os_snprintf(pos, end - pos, "[MESH]");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return -1;
pos += ret;
}
if (bss_is_dmg(bss)) {
const char *s;
ret = os_snprintf(pos, end - pos, "[DMG]");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return -1;
pos += ret;
switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
@ -2350,33 +2350,33 @@ static int wpa_supplicant_ctrl_iface_scan_result(
break;
}
ret = os_snprintf(pos, end - pos, "%s", s);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return -1;
pos += ret;
} else {
if (bss->caps & IEEE80211_CAP_IBSS) {
ret = os_snprintf(pos, end - pos, "[IBSS]");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return -1;
pos += ret;
}
if (bss->caps & IEEE80211_CAP_ESS) {
ret = os_snprintf(pos, end - pos, "[ESS]");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return -1;
pos += ret;
}
}
if (p2p) {
ret = os_snprintf(pos, end - pos, "[P2P]");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return -1;
pos += ret;
}
#ifdef CONFIG_HS20
if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
ret = os_snprintf(pos, end - pos, "[HS20]");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return -1;
pos += ret;
}
@ -2384,12 +2384,12 @@ static int wpa_supplicant_ctrl_iface_scan_result(
ret = os_snprintf(pos, end - pos, "\t%s",
wpa_ssid_txt(bss->ssid, bss->ssid_len));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return -1;
pos += ret;
ret = os_snprintf(pos, end - pos, "\n");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return -1;
pos += ret;
@ -2408,7 +2408,7 @@ static int wpa_supplicant_ctrl_iface_scan_results(
end = buf + buflen;
ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
"flags / ssid\n");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
@ -2627,7 +2627,7 @@ static int wpa_supplicant_ctrl_iface_add_network(
wpa_config_set_network_defaults(ssid);
ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
if (ret < 0 || (size_t) ret >= buflen)
if (os_snprintf_error(buflen, ret))
return -1;
return ret;
}
@ -2909,7 +2909,7 @@ static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
end = buf + buflen;
ret = os_snprintf(pos, end - pos,
"cred id / realm / username / domain / imsi\n");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
@ -2920,7 +2920,7 @@ static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
cred->username ? cred->username : "",
cred->domain ? cred->domain[0] : "",
cred->imsi ? cred->imsi : "");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
@ -2946,7 +2946,7 @@ static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
ret = os_snprintf(buf, buflen, "%d\n", cred->id);
if (ret < 0 || (size_t) ret >= buflen)
if (os_snprintf_error(buflen, ret))
return -1;
return ret;
}
@ -3208,7 +3208,7 @@ static int ctrl_iface_get_capability_pairwise(int res, char *strict,
ret = os_snprintf(pos, end - pos, "%s%s",
pos == buf ? "" : " ",
ciphers[i].name);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -3244,7 +3244,7 @@ static int ctrl_iface_get_capability_group(int res, char *strict,
ret = os_snprintf(pos, end - pos, "%s%s",
pos == buf ? "" : " ",
ciphers[i].name);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -3276,14 +3276,14 @@ static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
}
ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
ret = os_snprintf(pos, end - pos, " WPA-EAP");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -3291,14 +3291,14 @@ static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
ret = os_snprintf(pos, end - pos, " WPA-PSK");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
ret = os_snprintf(pos, end - pos, " WPA-NONE");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -3331,7 +3331,7 @@ static int ctrl_iface_get_capability_proto(int res, char *strict,
WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
ret = os_snprintf(pos, end - pos, "%sRSN",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -3340,7 +3340,7 @@ static int ctrl_iface_get_capability_proto(int res, char *strict,
WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
ret = os_snprintf(pos, end - pos, "%sWPA",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -3372,7 +3372,7 @@ static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
ret = os_snprintf(pos, end - pos, "%sOPEN",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -3380,7 +3380,7 @@ static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
ret = os_snprintf(pos, end - pos, "%sSHARED",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -3388,7 +3388,7 @@ static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
ret = os_snprintf(pos, end - pos, "%sLEAP",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -3420,7 +3420,7 @@ static int ctrl_iface_get_capability_modes(int res, char *strict,
if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
ret = os_snprintf(pos, end - pos, "%sIBSS",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -3428,7 +3428,7 @@ static int ctrl_iface_get_capability_modes(int res, char *strict,
if (capa->flags & WPA_DRIVER_FLAGS_AP) {
ret = os_snprintf(pos, end - pos, "%sAP",
pos == buf ? "" : " ");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -3465,7 +3465,7 @@ static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
continue;
}
ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
chnl = wpa_s->hw.modes[j].channels;
@ -3473,12 +3473,12 @@ static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
continue;
ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
ret = os_snprintf(pos, end - pos, "\n");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -3516,7 +3516,7 @@ static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
}
ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
hmode);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
chnl = wpa_s->hw.modes[j].channels;
@ -3530,12 +3530,12 @@ static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
chnl[i].flag & HOSTAPD_CHAN_RADAR ?
" (DFS)" : "");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
ret = os_snprintf(pos, end - pos, "\n");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -3612,7 +3612,7 @@ static int wpa_supplicant_ctrl_iface_get_capability(
#ifdef CONFIG_ERP
if (os_strcmp(field, "erp") == 0) {
res = os_snprintf(buf, buflen, "ERP");
if (res < 0 || (unsigned int) res >= buflen)
if (os_snprintf_error(buflen, res))
return -1;
return res;
}
@ -3638,20 +3638,20 @@ static char * anqp_add_hex(char *pos, char *end, const char *title,
return start;
ret = os_snprintf(pos, end - pos, "%s=", title);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return start;
pos += ret;
d = wpabuf_head_u8(data);
for (i = 0; i < wpabuf_len(data); i++) {
ret = os_snprintf(pos, end - pos, "%02x", *d++);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return start;
pos += ret;
}
ret = os_snprintf(pos, end - pos, "\n");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return start;
pos += ret;
@ -3673,7 +3673,7 @@ static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
if (mask & WPA_BSS_MASK_ID) {
ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return 0;
pos += ret;
}
@ -3681,14 +3681,14 @@ static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
if (mask & WPA_BSS_MASK_BSSID) {
ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
MAC2STR(bss->bssid));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return 0;
pos += ret;
}
if (mask & WPA_BSS_MASK_FREQ) {
ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return 0;
pos += ret;
}
@ -3696,7 +3696,7 @@ static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
if (mask & WPA_BSS_MASK_BEACON_INT) {
ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
bss->beacon_int);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return 0;
pos += ret;
}
@ -3704,28 +3704,28 @@ static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
if (mask & WPA_BSS_MASK_CAPABILITIES) {
ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
bss->caps);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return 0;
pos += ret;
}
if (mask & WPA_BSS_MASK_QUAL) {
ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return 0;
pos += ret;
}
if (mask & WPA_BSS_MASK_NOISE) {
ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return 0;
pos += ret;
}
if (mask & WPA_BSS_MASK_LEVEL) {
ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return 0;
pos += ret;
}
@ -3733,7 +3733,7 @@ static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
if (mask & WPA_BSS_MASK_TSF) {
ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
(unsigned long long) bss->tsf);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return 0;
pos += ret;
}
@ -3744,34 +3744,34 @@ static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
os_get_reltime(&now);
ret = os_snprintf(pos, end - pos, "age=%d\n",
(int) (now.sec - bss->last_update.sec));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return 0;
pos += ret;
}
if (mask & WPA_BSS_MASK_IE) {
ret = os_snprintf(pos, end - pos, "ie=");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return 0;
pos += ret;
ie = (const u8 *) (bss + 1);
for (i = 0; i < bss->ie_len; i++) {
ret = os_snprintf(pos, end - pos, "%02x", *ie++);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return 0;
pos += ret;
}
ret = os_snprintf(pos, end - pos, "\n");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return 0;
pos += ret;
}
if (mask & WPA_BSS_MASK_FLAGS) {
ret = os_snprintf(pos, end - pos, "flags=");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return 0;
pos += ret;
@ -3786,14 +3786,14 @@ static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
ret = os_snprintf(pos, end - pos, "[WEP]");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return 0;
pos += ret;
}
if (bss_is_dmg(bss)) {
const char *s;
ret = os_snprintf(pos, end - pos, "[DMG]");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return 0;
pos += ret;
switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
@ -3811,19 +3811,19 @@ static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
break;
}
ret = os_snprintf(pos, end - pos, "%s", s);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return 0;
pos += ret;
} else {
if (bss->caps & IEEE80211_CAP_IBSS) {
ret = os_snprintf(pos, end - pos, "[IBSS]");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return 0;
pos += ret;
}
if (bss->caps & IEEE80211_CAP_ESS) {
ret = os_snprintf(pos, end - pos, "[ESS]");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return 0;
pos += ret;
}
@ -3831,21 +3831,21 @@ static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
ret = os_snprintf(pos, end - pos, "[P2P]");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return 0;
pos += ret;
}
#ifdef CONFIG_HS20
if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
ret = os_snprintf(pos, end - pos, "[HS20]");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return 0;
pos += ret;
}
#endif /* CONFIG_HS20 */
ret = os_snprintf(pos, end - pos, "\n");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return 0;
pos += ret;
}
@ -3853,7 +3853,7 @@ static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
if (mask & WPA_BSS_MASK_SSID) {
ret = os_snprintf(pos, end - pos, "ssid=%s\n",
wpa_ssid_txt(bss->ssid, bss->ssid_len));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return 0;
pos += ret;
}
@ -3886,7 +3886,7 @@ static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
WFD_IE_VENDOR_TYPE);
if (wfd) {
ret = os_snprintf(pos, end - pos, "wfd_subelems=");
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
wpabuf_free(wfd);
return 0;
}
@ -3898,7 +3898,7 @@ static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
wpabuf_free(wfd);
ret = os_snprintf(pos, end - pos, "\n");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return 0;
pos += ret;
}
@ -3948,7 +3948,7 @@ static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
if (mask & WPA_BSS_MASK_DELIM) {
ret = os_snprintf(pos, end - pos, "====\n");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return 0;
pos += ret;
}
@ -4358,7 +4358,7 @@ static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
return -1;
if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
ret = os_snprintf(buf, buflen, "%08d", new_pin);
if (ret < 0 || (size_t) ret >= buflen)
if (os_snprintf_error(buflen, ret))
return -1;
return ret;
}
@ -4473,7 +4473,7 @@ static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
if (ref == 0)
return -1;
res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
if (res < 0 || (unsigned) res >= buflen)
if (os_snprintf_error(buflen, res))
return -1;
return res;
}
@ -4909,7 +4909,7 @@ static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
info->dev_capab,
info->group_capab,
info->level);
if (res < 0 || res >= end - pos)
if (os_snprintf_error(end - pos, res))
return pos - buf;
pos += res;
@ -4920,7 +4920,7 @@ static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
wps_dev_type_bin2str(t, devtype,
sizeof(devtype)));
if (res < 0 || res >= end - pos)
if (os_snprintf_error(end - pos, res))
return pos - buf;
pos += res;
}
@ -4928,7 +4928,7 @@ static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
if (ssid) {
res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
if (res < 0 || res >= end - pos)
if (os_snprintf_error(end - pos, res))
return pos - buf;
pos += res;
}
@ -4940,7 +4940,7 @@ static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
if (info->vendor_elems) {
res = os_snprintf(pos, end - pos, "vendor_elems=");
if (res < 0 || res >= end - pos)
if (os_snprintf_error(end - pos, res))
return pos - buf;
pos += res;
@ -4949,7 +4949,7 @@ static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
wpabuf_len(info->vendor_elems));
res = os_snprintf(pos, end - pos, "\n");
if (res < 0 || res >= end - pos)
if (os_snprintf_error(end - pos, res))
return pos - buf;
pos += res;
}
@ -5804,7 +5804,7 @@ static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
if (si.avg_signal) {
ret = os_snprintf(pos, end - pos,
"AVG_RSSI=%d\n", si.avg_signal);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return -1;
pos += ret;
}
@ -6023,7 +6023,7 @@ static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
work->type, work->wpa_s->ifname, work->freq,
work->started, diff.sec, diff.usec);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
break;
pos += ret;
}
@ -6119,7 +6119,7 @@ static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
}
ret = os_snprintf(buf, buflen, "%u", ework->id);
if (ret < 0 || (size_t) ret >= buflen)
if (os_snprintf_error(buflen, ret))
return -1;
return ret;
}
@ -7690,7 +7690,7 @@ static int wpa_supplicant_global_iface_list(struct wpa_global *global,
res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
tmp->drv_name, tmp->ifname,
tmp->desc ? tmp->desc : "");
if (res < 0 || res >= end - pos) {
if (os_snprintf_error(end - pos, res)) {
*pos = '\0';
break;
}
@ -7716,7 +7716,7 @@ static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
while (wpa_s) {
res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
if (res < 0 || res >= end - pos) {
if (os_snprintf_error(end - pos, res)) {
*pos = '\0';
break;
}
@ -7931,12 +7931,12 @@ static int wpas_global_ctrl_iface_status(struct wpa_global *global,
"p2p_state=%s\n",
MAC2STR(global->p2p_dev_addr),
p2p_get_state_txt(global->p2p));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
} else if (global->p2p) {
ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -7945,7 +7945,7 @@ static int wpas_global_ctrl_iface_status(struct wpa_global *global,
#ifdef CONFIG_WIFI_DISPLAY
ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
!!global->wifi_display);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
#endif /* CONFIG_WIFI_DISPLAY */
@ -7954,7 +7954,7 @@ static int wpas_global_ctrl_iface_status(struct wpa_global *global,
ret = os_snprintf(pos, end - pos, "ifname=%s\n"
"address=" MACSTR "\n",
wpa_s->ifname, MAC2STR(wpa_s->own_addr));
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}

@ -272,7 +272,7 @@ static char * wpa_supplicant_ctrl_iface_path(struct wpa_supplicant *wpa_s)
}
res = os_snprintf(buf, len, "%s/%s", dir, wpa_s->ifname);
if (res < 0 || (size_t) res >= len) {
if (os_snprintf_error(len, res)) {
os_free(pbuf);
os_free(buf);
return NULL;
@ -671,7 +671,7 @@ static void wpa_supplicant_ctrl_iface_send(struct wpa_supplicant *wpa_s,
return;
res = os_snprintf(levelstr, sizeof(levelstr), "<%d>", level);
if (res < 0 || (size_t) res >= sizeof(levelstr))
if (os_snprintf_error(sizeof(levelstr), res))
return;
idx = 0;
if (ifname) {

@ -136,7 +136,7 @@ static int is_signature_correct(DBusMessage *message,
if (arg->dir == ARG_IN) {
size_t blen = registered_sig + MAX_SIG_LEN - pos;
ret = os_snprintf(pos, blen, "%s", arg->type);
if (ret < 0 || (size_t) ret >= blen)
if (os_snprintf_error(blen, ret))
return 0;
pos += ret;
}

@ -461,7 +461,7 @@ static void eapol_test_eap_param_needed(void *ctx, enum wpa_ctrl_req_type field,
len = os_snprintf(buf, buflen,
WPA_CTRL_REQ "%s-%d:%s needed for SSID ",
field_name, ssid->id, txt);
if (len < 0 || (size_t) len >= buflen) {
if (os_snprintf_error(buflen, len)) {
os_free(buf);
return;
}

@ -403,7 +403,7 @@ static int mesh_attr_text(const u8 *ies, size_t ies_len, char *buf, char *end)
mesh_id[elems.mesh_id_len] = '\0';
ret = os_snprintf(pos, end - pos, "mesh_id=%s\n", mesh_id);
os_free(mesh_id);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
@ -420,7 +420,7 @@ static int mesh_attr_text(const u8 *ies, size_t ies_len, char *buf, char *end)
elems.mesh_config[2], elems.mesh_config[3],
elems.mesh_config[4], elems.mesh_config[5],
elems.mesh_config[6]);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
@ -446,20 +446,20 @@ static int mesh_attr_text(const u8 *ies, size_t ies_len, char *buf, char *end)
if (bss_basic_rate_set_len > 0) {
ret = os_snprintf(pos, end - pos, "bss_basic_rate_set=%d",
bss_basic_rate_set[0]);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
for (i = 1; i < bss_basic_rate_set_len; i++) {
ret = os_snprintf(pos, end - pos, " %d",
bss_basic_rate_set[i]);
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}
ret = os_snprintf(pos, end - pos, "\n");
if (ret < 0 || ret >= end - pos)
if (os_snprintf_error(end - pos, ret))
return pos - buf;
pos += ret;
}

@ -333,7 +333,7 @@ static int wpa_cli_open_connection(const char *ifname, int attach)
return -1;
res = os_snprintf(cfile, flen, "%s/%s", ctrl_iface_dir,
ifname);
if (res < 0 || res >= flen) {
if (os_snprintf_error(flen, res)) {
os_free(cfile);
return -1;
}
@ -448,13 +448,13 @@ static int write_cmd(char *buf, size_t buflen, const char *cmd, int argc,
end = buf + buflen;
res = os_snprintf(pos, end - pos, "%s", cmd);
if (res < 0 || res >= end - pos)
if (os_snprintf_error(end - pos, res))
goto fail;
pos += res;
for (i = 0; i < argc; i++) {
res = os_snprintf(pos, end - pos, " %s", argv[i]);
if (res < 0 || res >= end - pos)
if (os_snprintf_error(end - pos, res))
goto fail;
pos += res;
}
@ -1085,14 +1085,14 @@ static int wpa_cli_cmd_identity(struct wpa_ctrl *ctrl, int argc, char *argv[])
pos = cmd;
ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "IDENTITY-%s:%s",
argv[0], argv[1]);
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
printf("Too long IDENTITY command.\n");
return -1;
}
pos += ret;
for (i = 2; i < argc; i++) {
ret = os_snprintf(pos, end - pos, " %s", argv[i]);
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
printf("Too long IDENTITY command.\n");
return -1;
}
@ -1118,14 +1118,14 @@ static int wpa_cli_cmd_password(struct wpa_ctrl *ctrl, int argc, char *argv[])
pos = cmd;
ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "PASSWORD-%s:%s",
argv[0], argv[1]);
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
printf("Too long PASSWORD command.\n");
return -1;
}
pos += ret;
for (i = 2; i < argc; i++) {
ret = os_snprintf(pos, end - pos, " %s", argv[i]);
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
printf("Too long PASSWORD command.\n");
return -1;
}
@ -1152,14 +1152,14 @@ static int wpa_cli_cmd_new_password(struct wpa_ctrl *ctrl, int argc,
pos = cmd;
ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "NEW_PASSWORD-%s:%s",
argv[0], argv[1]);
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
printf("Too long NEW_PASSWORD command.\n");
return -1;
}
pos += ret;
for (i = 2; i < argc; i++) {
ret = os_snprintf(pos, end - pos, " %s", argv[i]);
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
printf("Too long NEW_PASSWORD command.\n");
return -1;
}
@ -1185,14 +1185,14 @@ static int wpa_cli_cmd_pin(struct wpa_ctrl *ctrl, int argc, char *argv[])
pos = cmd;
ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "PIN-%s:%s",
argv[0], argv[1]);
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
printf("Too long PIN command.\n");
return -1;
}
pos += ret;
for (i = 2; i < argc; i++) {
ret = os_snprintf(pos, end - pos, " %s", argv[i]);
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
printf("Too long PIN command.\n");
return -1;
}
@ -1217,14 +1217,14 @@ static int wpa_cli_cmd_otp(struct wpa_ctrl *ctrl, int argc, char *argv[])
pos = cmd;
ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "OTP-%s:%s",
argv[0], argv[1]);
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
printf("Too long OTP command.\n");
return -1;
}
pos += ret;
for (i = 2; i < argc; i++) {
ret = os_snprintf(pos, end - pos, " %s", argv[i]);
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
printf("Too long OTP command.\n");
return -1;
}
@ -1250,14 +1250,14 @@ static int wpa_cli_cmd_sim(struct wpa_ctrl *ctrl, int argc, char *argv[])
pos = cmd;
ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "SIM-%s:%s",
argv[0], argv[1]);
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
printf("Too long SIM command.\n");
return -1;
}
pos += ret;
for (i = 2; i < argc; i++) {
ret = os_snprintf(pos, end - pos, " %s", argv[i]);
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
printf("Too long SIM command.\n");
return -1;
}
@ -1283,14 +1283,14 @@ static int wpa_cli_cmd_passphrase(struct wpa_ctrl *ctrl, int argc,
pos = cmd;
ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "PASSPHRASE-%s:%s",
argv[0], argv[1]);
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
printf("Too long PASSPHRASE command.\n");
return -1;
}
pos += ret;
for (i = 2; i < argc; i++) {
ret = os_snprintf(pos, end - pos, " %s", argv[i]);
if (ret < 0 || ret >= end - pos) {
if (os_snprintf_error(end - pos, ret)) {
printf("Too long PASSPHRASE command.\n");
return -1;
}
@ -1626,7 +1626,7 @@ static int wpa_cli_cmd_interface_add(struct wpa_ctrl *ctrl, int argc,
argc > 1 ? argv[1] : "", argc > 2 ? argv[2] : "",
argc > 3 ? argv[3] : "", argc > 4 ? argv[4] : "",
argc > 5 ? argv[5] : "");
if (res < 0 || (size_t) res >= sizeof(cmd))
if (os_snprintf_error(sizeof(cmd), res))
return -1;
cmd[sizeof(cmd) - 1] = '\0';
return wpa_ctrl_command(ctrl, cmd);
@ -1933,7 +1933,7 @@ static int wpa_cli_cmd_p2p_serv_disc_resp(struct wpa_ctrl *ctrl, int argc,
res = os_snprintf(cmd, sizeof(cmd), "P2P_SERV_DISC_RESP %s %s %s %s",
argv[0], argv[1], argv[2], argv[3]);
if (res < 0 || (size_t) res >= sizeof(cmd))
if (os_snprintf_error(sizeof(cmd), res))
return -1;
cmd[sizeof(cmd) - 1] = '\0';
return wpa_ctrl_command(ctrl, cmd);
@ -1981,7 +1981,7 @@ static int wpa_cli_cmd_p2p_service_add(struct wpa_ctrl *ctrl, int argc,
res = os_snprintf(cmd, sizeof(cmd),
"P2P_SERVICE_ADD %s %s %s",
argv[0], argv[1], argv[2]);
if (res < 0 || (size_t) res >= sizeof(cmd))
if (os_snprintf_error(sizeof(cmd), res))
return -1;
cmd[sizeof(cmd) - 1] = '\0';
return wpa_ctrl_command(ctrl, cmd);
@ -2008,7 +2008,7 @@ static int wpa_cli_cmd_p2p_service_del(struct wpa_ctrl *ctrl, int argc,
res = os_snprintf(cmd, sizeof(cmd),
"P2P_SERVICE_DEL %s %s",
argv[0], argv[1]);
if (res < 0 || (size_t) res >= sizeof(cmd))
if (os_snprintf_error(sizeof(cmd), res))
return -1;
cmd[sizeof(cmd) - 1] = '\0';
return wpa_ctrl_command(ctrl, cmd);
@ -2230,7 +2230,7 @@ static int wpa_cli_cmd_wfd_subelem_set(struct wpa_ctrl *ctrl, int argc,
res = os_snprintf(cmd, sizeof(cmd), "WFD_SUBELEM_SET %s %s",
argv[0], argc > 1 ? argv[1] : "");
if (res < 0 || (size_t) res >= sizeof(cmd))
if (os_snprintf_error(sizeof(cmd), res))
return -1;
cmd[sizeof(cmd) - 1] = '\0';
return wpa_ctrl_command(ctrl, cmd);
@ -2251,7 +2251,7 @@ static int wpa_cli_cmd_wfd_subelem_get(struct wpa_ctrl *ctrl, int argc,
res = os_snprintf(cmd, sizeof(cmd), "WFD_SUBELEM_GET %s",
argv[0]);
if (res < 0 || (size_t) res >= sizeof(cmd))
if (os_snprintf_error(sizeof(cmd), res))
return -1;
cmd[sizeof(cmd) - 1] = '\0';
return wpa_ctrl_command(ctrl, cmd);

@ -800,7 +800,7 @@ static void wpa_supplicant_eap_param_needed(void *ctx,
len = os_snprintf(buf, buflen,
WPA_CTRL_REQ "%s-%d:%s needed for SSID ",
field_name, ssid->id, txt);
if (len < 0 || (size_t) len >= buflen) {
if (os_snprintf_error(buflen, len)) {
os_free(buf);
return;
}

@ -1254,7 +1254,7 @@ int wpas_wps_start_reg(struct wpa_supplicant *wpa_s, const u8 *bssid,
pos = val;
end = pos + sizeof(val);
res = os_snprintf(pos, end - pos, "\"pin=%s", pin);
if (res < 0 || res >= end - pos)
if (os_snprintf_error(end - pos, res))
return -1;
pos += res;
if (settings) {
@ -1262,12 +1262,12 @@ int wpas_wps_start_reg(struct wpa_supplicant *wpa_s, const u8 *bssid,
"new_encr=%s new_key=%s",
settings->ssid_hex, settings->auth,
settings->encr, settings->key_hex);
if (res < 0 || res >= end - pos)
if (os_snprintf_error(end - pos, res))
return -1;
pos += res;
}
res = os_snprintf(pos, end - pos, "\"");
if (res < 0 || res >= end - pos)
if (os_snprintf_error(end - pos, res))
return -1;
if (wpa_config_set(ssid, "phase1", val, 0) < 0)
return -1;

Loading…
Cancel
Save