1 Upstream-Status: Inappropriate [not used]
3 --- dbus_dict_helpers.c.array-fix 2006-12-18 12:31:11.000000000 -0500
4 +++ dbus_dict_helpers.c 2006-12-20 03:17:08.000000000 -0500
5 @@ -629,36 +629,55 @@ dbus_bool_t wpa_dbus_dict_open_read(DBus
9 +#define BYTE_ARRAY_CHUNK_SIZE 34
10 +#define BYTE_ARRAY_ITEM_SIZE (sizeof (char))
12 static dbus_bool_t _wpa_dbus_dict_entry_get_byte_array(
13 - DBusMessageIter *iter, int array_len, int array_type,
14 + DBusMessageIter *iter, int array_type,
15 struct wpa_dbus_dict_entry *entry)
17 - dbus_uint32_t i = 0;
18 + dbus_uint32_t count = 0;
19 dbus_bool_t success = FALSE;
23 - /* Zero-length arrays are valid. */
24 - if (array_len == 0) {
25 - entry->bytearray_value = NULL;
26 - entry->array_type = DBUS_TYPE_BYTE;
30 + entry->bytearray_value = NULL;
31 + entry->array_type = DBUS_TYPE_BYTE;
33 - entry->bytearray_value = wpa_zalloc(array_len * sizeof(char));
34 - if (!entry->bytearray_value) {
35 + buffer = wpa_zalloc(BYTE_ARRAY_ITEM_SIZE * BYTE_ARRAY_CHUNK_SIZE);
37 perror("_wpa_dbus_dict_entry_get_byte_array[dbus]: out of "
42 - entry->array_type = DBUS_TYPE_BYTE;
43 - entry->array_len = array_len;
44 + entry->bytearray_value = buffer;
45 + entry->array_len = 0;
46 while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_BYTE) {
49 + if ((count % BYTE_ARRAY_CHUNK_SIZE) == 0 && count != 0) {
50 + buffer = realloc(buffer, BYTE_ARRAY_ITEM_SIZE * (count + BYTE_ARRAY_CHUNK_SIZE));
51 + if (buffer == NULL) {
52 + perror("_wpa_dbus_dict_entry_get_byte_array["
53 + "dbus] out of memory trying to "
54 + "retrieve the string array");
58 + entry->bytearray_value = buffer;
60 dbus_message_iter_get_basic(iter, &byte);
61 - entry->bytearray_value[i++] = byte;
62 + entry->bytearray_value[count] = byte;
63 + entry->array_len = ++count;
64 dbus_message_iter_next(iter);
67 + /* Zero-length arrays are valid. */
68 + if (entry->array_len == 0) {
69 + free(entry->bytearray_value);
70 + entry->strarray_value = NULL;
76 @@ -666,8 +685,11 @@ done:
80 +#define STR_ARRAY_CHUNK_SIZE 8
81 +#define STR_ARRAY_ITEM_SIZE (sizeof (char *))
83 static dbus_bool_t _wpa_dbus_dict_entry_get_string_array(
84 - DBusMessageIter *iter, int array_len, int array_type,
85 + DBusMessageIter *iter, int array_type,
86 struct wpa_dbus_dict_entry *entry)
88 dbus_uint32_t count = 0;
89 @@ -677,13 +699,7 @@ static dbus_bool_t _wpa_dbus_dict_entry_
90 entry->strarray_value = NULL;
91 entry->array_type = DBUS_TYPE_STRING;
93 - /* Zero-length arrays are valid. */
94 - if (array_len == 0) {
99 - buffer = wpa_zalloc(sizeof (char *) * 8);
100 + buffer = wpa_zalloc(STR_ARRAY_ITEM_SIZE * STR_ARRAY_CHUNK_SIZE);
101 if (buffer == NULL) {
102 perror("_wpa_dbus_dict_entry_get_string_array[dbus] out of "
103 "memory trying to retrieve a string array");
104 @@ -696,18 +712,14 @@ static dbus_bool_t _wpa_dbus_dict_entry_
108 - if ((count % 8) == 0 && count != 0) {
110 - tmp = realloc(buffer, sizeof(char *) * (count + 8));
112 + if ((count % STR_ARRAY_CHUNK_SIZE) == 0 && count != 0) {
113 + buffer = realloc(buffer, STR_ARRAY_ITEM_SIZE * (count + STR_ARRAY_CHUNK_SIZE));
114 + if (buffer == NULL) {
115 perror("_wpa_dbus_dict_entry_get_string_array["
116 "dbus] out of memory trying to "
117 "retrieve the string array");
124 entry->strarray_value = buffer;
126 @@ -723,6 +735,13 @@ static dbus_bool_t _wpa_dbus_dict_entry_
127 entry->array_len = ++count;
128 dbus_message_iter_next(iter);
131 + /* Zero-length arrays are valid. */
132 + if (entry->array_len == 0) {
133 + free(entry->strarray_value);
134 + entry->strarray_value = NULL;
140 @@ -734,7 +753,6 @@ static dbus_bool_t _wpa_dbus_dict_entry_
141 DBusMessageIter *iter_dict_val, struct wpa_dbus_dict_entry *entry)
143 int array_type = dbus_message_iter_get_element_type(iter_dict_val);
145 dbus_bool_t success = FALSE;
146 DBusMessageIter iter_array;
148 @@ -743,20 +761,14 @@ static dbus_bool_t _wpa_dbus_dict_entry_
150 dbus_message_iter_recurse(iter_dict_val, &iter_array);
152 - array_len = dbus_message_iter_get_array_len(&iter_array);
156 switch (array_type) {
158 success = _wpa_dbus_dict_entry_get_byte_array(&iter_array,
163 case DBUS_TYPE_STRING:
164 success = _wpa_dbus_dict_entry_get_string_array(&iter_array,
169 @@ -943,9 +955,17 @@ void wpa_dbus_dict_entry_clear(struct wp
171 case DBUS_TYPE_ARRAY:
172 switch (entry->array_type) {
173 - case DBUS_TYPE_BYTE:
174 - free(entry->bytearray_value);
176 + case DBUS_TYPE_BYTE: {
177 + free(entry->bytearray_value);
180 + case DBUS_TYPE_STRING: {
182 + for (i = 0; i < entry->array_len; i++)
183 + free (entry->strarray_value[i]);
184 + free (entry->strarray_value);