From a9aaacbb5081f41318ddb0fa597da6c29c6898df Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sun, 7 Dec 2014 12:11:13 +0200 Subject: [PATCH] Check os_snprintf() result more consistently - maximum length This adds verification of os_snprintf() result against the maximum buffer length. These changes were done automatically with spatch using the following semantic patch: @@ expression E1,E2,E3; statement S1; @@ E1 = os_snprintf(E2, E3, ...); - if (\( E1 < 0 \| E1 <= 0 \)) + if (os_snprintf_error(E3, E1)) ( S1 | { ... } ) Signed-off-by: Jouni Malinen --- src/drivers/driver_nl80211.c | 2 +- wpa_supplicant/dbus/dbus_new_handlers.c | 4 ++-- wpa_supplicant/dbus/dbus_old_handlers.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c index b8dd5778b..c5c33c8bd 100644 --- a/src/drivers/driver_nl80211.c +++ b/src/drivers/driver_nl80211.c @@ -7972,7 +7972,7 @@ static int linux_write_system_file(const char *path, unsigned int val) int fd, len; len = os_snprintf(buf, sizeof(buf), "%u\n", val); - if (len < 0) + if (os_snprintf_error(sizeof(buf), len)) return -1; fd = open(path, O_WRONLY); diff --git a/wpa_supplicant/dbus/dbus_new_handlers.c b/wpa_supplicant/dbus/dbus_new_handlers.c index eefc15d1d..6cf95d260 100644 --- a/wpa_supplicant/dbus/dbus_new_handlers.c +++ b/wpa_supplicant/dbus/dbus_new_handlers.c @@ -247,7 +247,7 @@ dbus_bool_t set_network_properties(struct wpa_supplicant *wpa_s, ret = os_snprintf(value, size, "%u", entry.uint32_value); - if (ret <= 0) + if (os_snprintf_error(size, ret)) goto error; } else if (entry.type == DBUS_TYPE_INT32) { value = os_zalloc(size); @@ -256,7 +256,7 @@ dbus_bool_t set_network_properties(struct wpa_supplicant *wpa_s, ret = os_snprintf(value, size, "%d", entry.int32_value); - if (ret <= 0) + if (os_snprintf_error(size, ret)) goto error; } else goto error; diff --git a/wpa_supplicant/dbus/dbus_old_handlers.c b/wpa_supplicant/dbus/dbus_old_handlers.c index 048158f2f..5f54cf141 100644 --- a/wpa_supplicant/dbus/dbus_old_handlers.c +++ b/wpa_supplicant/dbus/dbus_old_handlers.c @@ -981,7 +981,7 @@ DBusMessage * wpas_dbus_iface_set_network(DBusMessage *message, goto error; ret = os_snprintf(value, size, "%u", entry.uint32_value); - if (ret <= 0) + if (os_snprintf_error(size, ret)) goto error; } else if (entry.type == DBUS_TYPE_INT32) { value = os_zalloc(size); @@ -989,7 +989,7 @@ DBusMessage * wpas_dbus_iface_set_network(DBusMessage *message, goto error; ret = os_snprintf(value, size, "%d", entry.int32_value); - if (ret <= 0) + if (os_snprintf_error(size, ret)) goto error; } else goto error;