]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Check snprintf result to avoid compiler warnings
authorJouni Malinen <j@w1.fi>
Sun, 23 Dec 2018 22:44:36 +0000 (00:44 +0200)
committerJouni Malinen <j@w1.fi>
Mon, 24 Dec 2018 09:09:22 +0000 (11:09 +0200)
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>
src/ap/eap_user_db.c
src/ap/vlan_init.c
src/drivers/driver_wext.c
wpa_supplicant/dbus/dbus_new_handlers_p2p.c
wpa_supplicant/dbus/dbus_new_handlers_wps.c
wpa_supplicant/dbus/dbus_old_handlers_wps.c

index 1c26fe3b6a099f9765502db46a2c44674b6bebac..a510ee3e29fdc5cacbf8da7af4222cb6ed185b60 100644 (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;
index ce37fdaf9078ee92bb8541609c310f4ed298f4a3..e293a003303f90db19f588cf8c293247f8c7bd63 100644 (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;
index 20abaab4cd84c2c857ac7a29a3904e610334e6fc..888ea89f39703ddcb249acbfe4a4288faa809a80 100644 (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)
index 9305b9a4f37d6ff5c8fbfa805811dd379b7badc0..33f02a7982b5457714809db60f30c70cab8e944b 100644 (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,
index f762b3f2ef5ca431077095a14f06f19dfa41bfa7..19c1a6157f6d47ffc07386e39ae1ba62a9c865f0 100644 (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);
        }
index 5309a5301fc24225778fd5e4d34ca6cbf4748540..987e12d9cf9a03d6d9a7a3408131fd3e03628a0d 100644 (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,