]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Check os_snprintf() result more consistently - automatic 2
authorJouni Malinen <j@w1.fi>
Mon, 8 Dec 2014 09:18:39 +0000 (11:18 +0200)
committerJouni Malinen <j@w1.fi>
Mon, 8 Dec 2014 09:42:07 +0000 (11:42 +0200)
This converts os_snprintf() result validation cases to use
os_snprintf_error() where the comparison was 'res > size' instead of
'res >= size'. These changes were done automatically with spatch using
the following semantic patch:

@@
identifier E1;
expression E2,E3,E4,E5,E6;
statement S1;
@@

(
  E1 = os_snprintf(E2, E3, ...);
|
  int E1 = os_snprintf(E2, E3, ...);
|
  if (E5)
E1 = os_snprintf(E2, E3, ...);
  else
E1 = os_snprintf(E2, E3, ...);
|
  if (E5)
E1 = os_snprintf(E2, E3, ...);
  else if (E6)
E1 = os_snprintf(E2, E3, ...);
  else
E1 = 0;
|
  if (E5) {
...
E1 = os_snprintf(E2, E3, ...);
  } else {
...
return -1;
  }
|
  if (E5) {
...
E1 = os_snprintf(E2, E3, ...);
  } else if (E6) {
...
E1 = os_snprintf(E2, E3, ...);
  } else {
...
return -1;
  }
|
  if (E5) {
...
E1 = os_snprintf(E2, E3, ...);
  } else {
...
E1 = os_snprintf(E2, E3, ...);
  }
)
? os_free(E4);
- if (E1 < 0 || \( E1 > E3 \| (size_t) E1 > E3 \| E1 > (int) E3 \))
+ if (os_snprintf_error(E3, E1))
(
  S1
|
{ ... }
)

Signed-off-by: Jouni Malinen <j@w1.fi>
src/utils/common.c
wpa_supplicant/ctrl_iface.c
wpa_supplicant/dbus/dbus_dict_helpers.c

index 1517a487c6bcf37d9f81a773686fec21f74e9145..422b476c3e24088da6fcc22c6dbbf3b177c81265 100644 (file)
@@ -755,7 +755,7 @@ char * freq_range_list_str(const struct wpa_freq_range_list *list)
                        res = os_snprintf(pos, end - pos, "%s%u-%u",
                                          i == 0 ? "" : ",",
                                          range->min, range->max);
-               if (res < 0 || res > end - pos) {
+               if (os_snprintf_error(end - pos, res)) {
                        os_free(buf);
                        return NULL;
                }
index e9527752639b9245c71ee06f53c3538093226d96..c96052b66d60f3f738c30f5efb46bc4d81c2247f 100644 (file)
@@ -642,7 +642,7 @@ static int ctrl_iface_get_capability_tdls(
                          (wpa_s->drv_flags &
                           WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
                           "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
-       if (ret < 0 || (size_t) ret > buflen)
+       if (os_snprintf_error(buflen, ret))
                return -1;
        return ret;
 }
@@ -5780,14 +5780,14 @@ static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
                          "NOISE=%d\nFREQUENCY=%u\n",
                          si.current_signal, si.current_txrate / 1000,
                          si.current_noise, si.frequency);
-       if (ret < 0 || ret > end - pos)
+       if (os_snprintf_error(end - pos, ret))
                return -1;
        pos += ret;
 
        if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
                ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
                                  channel_width_to_string(si.chanwidth));
-               if (ret < 0 || ret > end - pos)
+               if (os_snprintf_error(end - pos, ret))
                        return -1;
                pos += ret;
        }
@@ -5796,7 +5796,7 @@ static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
                ret = os_snprintf(pos, end - pos,
                                  "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
                                  si.center_frq1, si.center_frq2);
-               if (ret < 0 || ret > end - pos)
+               if (os_snprintf_error(end - pos, ret))
                        return -1;
                pos += ret;
        }
@@ -5825,7 +5825,7 @@ static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
 
        ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
                          sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
-       if (ret < 0 || (size_t) ret > buflen)
+       if (os_snprintf_error(buflen, ret))
                return -1;
        return ret;
 }
index 949ce7c91a67696c4529ab4be0f654045e4c13cc..034b751c4c33d0e65bd4e04e2608d3e66c1fa410 100644 (file)
@@ -465,7 +465,7 @@ dbus_bool_t wpa_dbus_dict_begin_array(DBusMessageIter *iter_dict,
        err = os_snprintf(array_type, sizeof(array_type),
                          DBUS_TYPE_ARRAY_AS_STRING "%s",
                          type);
-       if (err < 0 || err > (int) sizeof(array_type))
+       if (os_snprintf_error(sizeof(array_type), err))
                return FALSE;
 
        if (!iter_dict || !iter_dict_entry || !iter_dict_val || !iter_array)