summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar shtrophic2025-02-22 11:40:54 +0000
committerGravatar shtrophic2025-02-22 11:40:54 +0000
commitbeb500360c32ee459201a087dbed57a447b1f0db (patch)
treecde2f140812aa913bc8668fc2e0dad9ec1b2211c
parentduping isn't necessary as xs_vals are copied anyway (right?) (diff)
parentMerge pull request 'Fix memory leak in multipart parsing' (#307) from inz/sna... (diff)
downloadpenes-snac2-beb500360c32ee459201a087dbed57a447b1f0db.tar.gz
penes-snac2-beb500360c32ee459201a087dbed57a447b1f0db.tar.xz
penes-snac2-beb500360c32ee459201a087dbed57a447b1f0db.zip
Merge branch 'master' into curl-smtp
-rw-r--r--xs.h7
-rw-r--r--xs_url.h20
2 files changed, 14 insertions, 13 deletions
diff --git a/xs.h b/xs.h
index b53885e..ab5a264 100644
--- a/xs.h
+++ b/xs.h
@@ -398,6 +398,7 @@ xs_val *xs_dup(const xs_val *data)
398xs_val *xs_expand(xs_val *data, int offset, int size) 398xs_val *xs_expand(xs_val *data, int offset, int size)
399/* opens a hole in data */ 399/* opens a hole in data */
400{ 400{
401 xstype type = xs_type(data);
401 int sz = xs_size(data); 402 int sz = xs_size(data);
402 int n; 403 int n;
403 404
@@ -410,9 +411,9 @@ xs_val *xs_expand(xs_val *data, int offset, int size)
410 for (n = sz - 1; n >= offset + size; n--) 411 for (n = sz - 1; n >= offset + size; n--)
411 data[n] = data[n - size]; 412 data[n] = data[n - size];
412 413
413 if (xs_type(data) == XSTYPE_LIST || 414 if (type == XSTYPE_LIST ||
414 xs_type(data) == XSTYPE_DICT || 415 type == XSTYPE_DICT ||
415 xs_type(data) == XSTYPE_DATA) 416 type == XSTYPE_DATA)
416 _xs_put_size(data, sz); 417 _xs_put_size(data, sz);
417 418
418 return data; 419 return data;
diff --git a/xs_url.h b/xs_url.h
index 37d2391..7bdff49 100644
--- a/xs_url.h
+++ b/xs_url.h
@@ -185,18 +185,16 @@ xs_dict *xs_multipart_form_data(const char *payload, int p_size, const char *hea
185 185
186 /* iterate searching the boundaries */ 186 /* iterate searching the boundaries */
187 while ((p = xs_memmem(payload + offset, p_size - offset, boundary, bsz)) != NULL) { 187 while ((p = xs_memmem(payload + offset, p_size - offset, boundary, bsz)) != NULL) {
188 xs *s1 = NULL; 188 xs *vn = NULL;
189 xs *l1 = NULL; 189 xs *fn = NULL;
190 const char *vn = NULL; 190 xs *ct = NULL;
191 const char *fn = NULL;
192 const char *ct = NULL;
193 char *q; 191 char *q;
194 int po, ps; 192 int po, ps;
195 193
196 /* final boundary? */ 194 /* final boundary? */
197 p += bsz; 195 p += bsz;
198 196
199 if (p[0] == '-' && p[1] == '-') 197 if ((p - payload) + 2 > p_size || (p[0] == '-' && p[1] == '-'))
200 break; 198 break;
201 199
202 /* skip the \r\n */ 200 /* skip the \r\n */
@@ -205,9 +203,11 @@ xs_dict *xs_multipart_form_data(const char *payload, int p_size, const char *hea
205 /* Tokodon sends also a Content-Type headers, 203 /* Tokodon sends also a Content-Type headers,
206 let's use it to determine the file type */ 204 let's use it to determine the file type */
207 do { 205 do {
208 if (p[0] == 13 && p[1] == 10) 206 xs *s1 = NULL;
207 xs *l1 = NULL;
208 if (p[0] == '\r' && p[1] == '\n')
209 break; 209 break;
210 q = strchr(p, '\r'); 210 q = memchr(p, '\r', p_size - (p - payload));
211 211
212 /* unexpected formatting, fail immediately */ 212 /* unexpected formatting, fail immediately */
213 if (q == NULL) 213 if (q == NULL)
@@ -222,12 +222,12 @@ xs_dict *xs_multipart_form_data(const char *payload, int p_size, const char *hea
222 l1 = xs_split(s1, "\""); 222 l1 = xs_split(s1, "\"");
223 223
224 /* get the variable name */ 224 /* get the variable name */
225 vn = xs_list_get(l1, 1); 225 vn = xs_dup(xs_list_get(l1, 1));
226 226
227 /* is it an attached file? */ 227 /* is it an attached file? */
228 if (xs_list_len(l1) >= 4 && strcmp(xs_list_get(l1, 2), "; filename=") == 0) { 228 if (xs_list_len(l1) >= 4 && strcmp(xs_list_get(l1, 2), "; filename=") == 0) {
229 /* get the file name */ 229 /* get the file name */
230 fn = xs_list_get(l1, 3); 230 fn = xs_dup(xs_list_get(l1, 3));
231 } 231 }
232 } 232 }
233 else 233 else