Check snprintf result to avoid compiler warnings

These do not really get truncated in practice, but it looks like some
newer compilers warn about the prints, so silence those by checking the
result and do something a bit more useful if the output would actually
get truncated.

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2018-12-24 00:44:36 +02:00
parent ee98dd631a
commit e422a819d0
6 changed files with 39 additions and 13 deletions

View file

@ -139,6 +139,7 @@ eap_user_sqlite_get(struct hostapd_data *hapd, const u8 *identity,
struct hostapd_eap_user *user = NULL;
char id_str[256], cmd[300];
size_t i;
int res;
if (identity_len >= sizeof(id_str)) {
wpa_printf(MSG_DEBUG, "%s: identity len too big: %d >= %d",
@ -183,9 +184,12 @@ eap_user_sqlite_get(struct hostapd_data *hapd, const u8 *identity,
return NULL;
}
os_snprintf(cmd, sizeof(cmd),
"SELECT * FROM users WHERE identity='%s' AND phase2=%d;",
id_str, phase2);
res = os_snprintf(cmd, sizeof(cmd),
"SELECT * FROM users WHERE identity='%s' AND phase2=%d;",
id_str, phase2);
if (os_snprintf_error(sizeof(cmd), res))
goto fail;
wpa_printf(MSG_DEBUG, "DB: %s", cmd);
if (sqlite3_exec(db, cmd, get_user_cb, &hapd->tmp_eap_user, NULL) !=
SQLITE_OK) {
@ -215,6 +219,7 @@ eap_user_sqlite_get(struct hostapd_data *hapd, const u8 *identity,
}
}
fail:
sqlite3_close(db);
return user;

View file

@ -187,6 +187,7 @@ struct hostapd_vlan * vlan_add_dynamic(struct hostapd_data *hapd,
{
struct hostapd_vlan *n;
char ifname[IFNAMSIZ + 1], *pos;
int ret;
if (vlan == NULL || vlan->vlan_id != VLAN_ID_WILDCARD)
return NULL;
@ -208,8 +209,12 @@ struct hostapd_vlan * vlan_add_dynamic(struct hostapd_data *hapd,
n->vlan_desc = *vlan_desc;
n->dynamic_vlan = 1;
os_snprintf(n->ifname, sizeof(n->ifname), "%s%d%s", ifname, vlan_id,
pos);
ret = os_snprintf(n->ifname, sizeof(n->ifname), "%s%d%s",
ifname, vlan_id, pos);
if (os_snprintf_error(sizeof(n->ifname), ret)) {
os_free(n);
return NULL;
}
os_strlcpy(n->bridge, vlan->bridge, sizeof(n->bridge));
n->next = hapd->conf->vlan;

View file

@ -868,14 +868,16 @@ static int wext_hostap_ifname(struct wpa_driver_wext_data *drv,
const char *ifname)
{
char buf[200], *res;
int type;
int type, ret;
FILE *f;
if (strcmp(ifname, ".") == 0 || strcmp(ifname, "..") == 0)
return -1;
snprintf(buf, sizeof(buf), "/sys/class/net/%s/device/net/%s/type",
drv->ifname, ifname);
ret = snprintf(buf, sizeof(buf), "/sys/class/net/%s/device/net/%s/type",
drv->ifname, ifname);
if (os_snprintf_error(sizeof(buf), ret))
return -1;
f = fopen(buf, "r");
if (!f)

View file

@ -532,6 +532,7 @@ DBusMessage * wpas_dbus_handler_p2p_connect(DBusMessage *message,
int new_pin;
char *err_msg = NULL;
char *iface = NULL;
int ret;
if (!wpa_dbus_p2p_check_enabled(wpa_s, message, &reply, NULL))
return reply;
@ -609,7 +610,12 @@ DBusMessage * wpas_dbus_handler_p2p_connect(DBusMessage *message,
char npin[9];
char *generated_pin;
os_snprintf(npin, sizeof(npin), "%08d", new_pin);
ret = os_snprintf(npin, sizeof(npin), "%08d", new_pin);
if (os_snprintf_error(sizeof(npin), ret)) {
reply = wpas_dbus_error_unknown_error(message,
"invalid PIN");
goto out;
}
generated_pin = npin;
reply = dbus_message_new_method_return(message);
dbus_message_append_args(reply, DBUS_TYPE_STRING,

View file

@ -286,8 +286,12 @@ DBusMessage * wpas_dbus_handler_wps_start(DBusMessage *message,
ret = wpas_wps_start_pin(wpa_s, params.bssid,
params.pin, 0,
DEV_PW_DEFAULT);
if (ret > 0)
os_snprintf(npin, sizeof(npin), "%08d", ret);
if (ret > 0) {
ret = os_snprintf(npin, sizeof(npin), "%08d", ret);
if (os_snprintf_error(sizeof(npin), ret))
return wpas_dbus_error_unknown_error(
message, "invalid PIN");
}
} else {
ret = wpas_wps_start_pbc(wpa_s, params.bssid, 0);
}

View file

@ -71,7 +71,7 @@ DBusMessage * wpas_dbus_iface_wps_pin(DBusMessage *message,
char *arg_bssid;
char *pin = NULL;
u8 bssid[ETH_ALEN], *_bssid = NULL;
int ret = 0;
int ret;
char npin[9];
if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg_bssid,
@ -105,7 +105,11 @@ DBusMessage * wpas_dbus_iface_wps_pin(DBusMessage *message,
return NULL;
if (ret > 0) {
os_snprintf(npin, sizeof(npin), "%08d", ret);
ret = os_snprintf(npin, sizeof(npin), "%08d", ret);
if (os_snprintf_error(sizeof(npin), ret))
return wpas_dbus_new_invalid_opts_error(message,
"invalid PIN");
pin = npin;
}
dbus_message_append_args(reply, DBUS_TYPE_STRING, &pin,