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 <j@w1.fi>
This commit is contained in:
Jouni Malinen 2014-12-07 12:11:13 +02:00
parent 0047306bc9
commit a9aaacbb50
3 changed files with 5 additions and 5 deletions

View file

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

View file

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

View file

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