]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
mime: make sure setting MIMEPOST to NULL resets properly
authorDaniel Stenberg <daniel@haxx.se>
Thu, 14 Jan 2021 15:31:42 +0000 (16:31 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 15 Jan 2021 07:33:27 +0000 (08:33 +0100)
... so that a function can first use MIMEPOST and then set it to NULL to
reset it back to a blank POST.

Added test 584 to verify the fix.

Reported-by: Christoph M. Becker
Fixes #6455
Closes #6456

lib/mime.c
tests/data/Makefile.inc
tests/data/test584 [new file with mode: 0644]
tests/libtest/Makefile.inc
tests/libtest/lib589.c

index 2ddd9b8b98de4bc31b7af6d300eb973eb921986b..abadcb02cba3e89007555aa23ac6038907c6c075 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -1168,6 +1168,7 @@ static void cleanup_part_content(curl_mimepart *part)
   part->kind = MIMEKIND_NONE;
   part->flags &= ~MIME_FAST_READ;
   part->lastreadstatus = 1; /* Successful read status. */
+  part->state.state = MIMESTATE_BEGIN;
 }
 
 static void mime_subparts_free(void *ptr)
index d0e6510b9ed7308b5dc8668eeac0cf960304e7cd..a6da863fa4b242af13660e07bc3a62123bb2a59d 100644 (file)
@@ -79,7 +79,7 @@ test545 test546 test547 test548 test549 test550 test551 test552 test553 \
 test554 test555 test556 test557 test558 test559 test560 test561 test562 \
 test563 test564 test565 test566 test567 test568 test569 test570 test571 \
 test572 test573 test574 test575 test576 test577 test578 test579 test580 \
-test581 test582 test583         test585 test586 test587 test588 test589 \
+test581 test582 test583 test584 test585 test586 test587 test588 test589 \
 test590 test591 test592 test593 test594 test595 test596 test597 test598 \
 test599 test600 test601 test602 test603 test604 test605 test606 test607 \
 test608 test609 test610 test611 test612 test613 test614 test615 test616 \
diff --git a/tests/data/test584 b/tests/data/test584
new file mode 100644 (file)
index 0000000..891e461
--- /dev/null
@@ -0,0 +1,81 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP POST
+HTTP MIME
+</keywords>
+</info>
+
+#
+# Server-side
+<reply>
+<data>
+HTTP/1.1 200 OK swsclose\r
+Date: Thu, 09 Nov 2010 14:49:00 GMT\r
+Server: test-server/fake\r
+Content-Length: 3\r
+\r
+OK
+</data>
+<datacheck>
+HTTP/1.1 200 OK swsclose\r
+Date: Thu, 09 Nov 2010 14:49:00 GMT\r
+Server: test-server/fake\r
+Content-Length: 3\r
+\r
+OK
+HTTP/1.1 200 OK swsclose\r
+Date: Thu, 09 Nov 2010 14:49:00 GMT\r
+Server: test-server/fake\r
+Content-Length: 3\r
+\r
+OK
+</datacheck>
+</reply>
+
+# Client-side
+<client>
+<server>
+http
+</server>
+# tool to invoke
+<tool>
+lib584
+</tool>
+
+ <name>
+CURLOPT_MIMEPOST first set then set to NULL
+ </name>
+ <command>
+http://%HOSTIP:%HTTPPORT/584
+</command>
+</client>
+
+#
+# Verify data after the test has been "shot"
+<verify>
+<strippart>
+s/^--------------------------[a-z0-9]*/--------------------------/
+s/boundary=------------------------[a-z0-9]*/boundary=------------------------/
+</strippart>
+<protocol>
+POST /584 HTTP/1.1\r
+Host: %HOSTIP:%HTTPPORT\r
+Accept: */*\r
+Content-Length: 144\r
+Content-Type: multipart/form-data; boundary=------------------------\r
+\r
+--------------------------\r
+Content-Disposition: form-data; name="fake"\r
+\r
+party\r
+----------------------------\r
+POST /584 HTTP/1.1\r
+Host: %HOSTIP:%HTTPPORT\r
+Accept: */*\r
+Content-Length: 0\r
+\r
+</protocol>
+</verify>
+</testcase>
index 28cf92ab7855e1d0b49321e9b6184194fccc309c..ef52e80f85bc56ffd6a981c2264a0b98c8cfec71 100644 (file)
@@ -44,7 +44,8 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect                \
  lib547 lib548 lib549 lib552 lib553 lib554 lib555 lib556 lib557 lib558   \
  lib559 lib560 lib562 lib564 lib565 lib566 lib567 lib568 lib569 lib570   \
  lib571 lib572 lib573 lib574 lib575 lib576        lib578 lib579 lib582   \
- lib583 lib585 lib586 lib587 lib589 lib590 lib591 lib597 lib598 lib599   \
+ lib583 lib584 lib585 lib586 lib587 lib589 lib590 lib591 lib597 lib598   \
+ lib599 \
  lib643 lib644 lib645 lib650 lib651 lib652 lib653 lib654 lib655 lib658   \
  lib659 lib661 lib666 lib667 lib668 \
  lib670 lib671 lib672 lib673 lib674 \
@@ -302,6 +303,9 @@ lib582_CPPFLAGS = $(AM_CPPFLAGS)
 lib583_SOURCES = lib583.c $(SUPPORTFILES)
 lib583_CPPFLAGS = $(AM_CPPFLAGS)
 
+lib584_SOURCES = lib589.c $(SUPPORTFILES)
+lib584_CPPFLAGS = $(AM_CPPFLAGS) -DLIB584
+
 lib585_SOURCES = lib500.c $(SUPPORTFILES) $(TESTUTIL) $(TSTTRACE) $(MULTIBYTE)
 lib585_LDADD = $(TESTUTIL_LIBS)
 lib585_CPPFLAGS = $(AM_CPPFLAGS) -DLIB585
index 43b1aee011331184af9d4d387493e425024d8a6e..06cc375f95d2590654688cc11318454a36c5830f 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -42,10 +42,23 @@ int test(char *URL)
 
   /* First set the URL that is about to receive our POST. */
   test_setopt(curl, CURLOPT_URL, URL);
-  test_setopt(curl, CURLOPT_MIMEPOST, NULL);
   test_setopt(curl, CURLOPT_VERBOSE, 1L); /* show verbose for debug */
   test_setopt(curl, CURLOPT_HEADER, 1L); /* include header */
 
+#ifdef LIB584
+  {
+    curl_mime *mime = curl_mime_init(curl);
+    curl_mimepart *part = curl_mime_addpart(mime);
+    curl_mime_name(part, "fake");
+    curl_mime_data(part, "party", 5);
+    test_setopt(curl, CURLOPT_MIMEPOST, mime);
+    res = curl_easy_perform(curl);
+    curl_mime_free(mime);
+  }
+#endif
+
+  test_setopt(curl, CURLOPT_MIMEPOST, NULL);
+
   /* Now, we should be making a zero byte POST request */
   res = curl_easy_perform(curl);