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

View File

@ -187,6 +187,7 @@ struct hostapd_vlan * vlan_add_dynamic(struct hostapd_data *hapd,
{ {
struct hostapd_vlan *n; struct hostapd_vlan *n;
char ifname[IFNAMSIZ + 1], *pos; char ifname[IFNAMSIZ + 1], *pos;
int ret;
if (vlan == NULL || vlan->vlan_id != VLAN_ID_WILDCARD) if (vlan == NULL || vlan->vlan_id != VLAN_ID_WILDCARD)
return NULL; return NULL;
@ -208,8 +209,12 @@ struct hostapd_vlan * vlan_add_dynamic(struct hostapd_data *hapd,
n->vlan_desc = *vlan_desc; n->vlan_desc = *vlan_desc;
n->dynamic_vlan = 1; n->dynamic_vlan = 1;
os_snprintf(n->ifname, sizeof(n->ifname), "%s%d%s", ifname, vlan_id, ret = os_snprintf(n->ifname, sizeof(n->ifname), "%s%d%s",
pos); 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)); os_strlcpy(n->bridge, vlan->bridge, sizeof(n->bridge));
n->next = hapd->conf->vlan; 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) const char *ifname)
{ {
char buf[200], *res; char buf[200], *res;
int type; int type, ret;
FILE *f; FILE *f;
if (strcmp(ifname, ".") == 0 || strcmp(ifname, "..") == 0) if (strcmp(ifname, ".") == 0 || strcmp(ifname, "..") == 0)
return -1; return -1;
snprintf(buf, sizeof(buf), "/sys/class/net/%s/device/net/%s/type", ret = snprintf(buf, sizeof(buf), "/sys/class/net/%s/device/net/%s/type",
drv->ifname, ifname); drv->ifname, ifname);
if (os_snprintf_error(sizeof(buf), ret))
return -1;
f = fopen(buf, "r"); f = fopen(buf, "r");
if (!f) if (!f)

View File

@ -532,6 +532,7 @@ DBusMessage * wpas_dbus_handler_p2p_connect(DBusMessage *message,
int new_pin; int new_pin;
char *err_msg = NULL; char *err_msg = NULL;
char *iface = NULL; char *iface = NULL;
int ret;
if (!wpa_dbus_p2p_check_enabled(wpa_s, message, &reply, NULL)) if (!wpa_dbus_p2p_check_enabled(wpa_s, message, &reply, NULL))
return reply; return reply;
@ -609,7 +610,12 @@ DBusMessage * wpas_dbus_handler_p2p_connect(DBusMessage *message,
char npin[9]; char npin[9];
char *generated_pin; 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; generated_pin = npin;
reply = dbus_message_new_method_return(message); reply = dbus_message_new_method_return(message);
dbus_message_append_args(reply, DBUS_TYPE_STRING, 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, ret = wpas_wps_start_pin(wpa_s, params.bssid,
params.pin, 0, params.pin, 0,
DEV_PW_DEFAULT); DEV_PW_DEFAULT);
if (ret > 0) 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_error_unknown_error(
message, "invalid PIN");
}
} else { } else {
ret = wpas_wps_start_pbc(wpa_s, params.bssid, 0); 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 *arg_bssid;
char *pin = NULL; char *pin = NULL;
u8 bssid[ETH_ALEN], *_bssid = NULL; u8 bssid[ETH_ALEN], *_bssid = NULL;
int ret = 0; int ret;
char npin[9]; char npin[9];
if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg_bssid, 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; return NULL;
if (ret > 0) { 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; pin = npin;
} }
dbus_message_append_args(reply, DBUS_TYPE_STRING, &pin, dbus_message_append_args(reply, DBUS_TYPE_STRING, &pin,