aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/test_postprocessor.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-10-30 08:35:28 +0000
committerChristian Grothoff <christian@grothoff.org>2013-10-30 08:35:28 +0000
commit3fb38e694808965356d6a02447d186107701fa24 (patch)
tree0442c555f8e27afe9c5ce7e4b34412c797a8b735 /src/microhttpd/test_postprocessor.c
parente524263be242e774d76377b04de9b033bd149d2e (diff)
downloadlibmicrohttpd-3fb38e694808965356d6a02447d186107701fa24.tar.gz
libmicrohttpd-3fb38e694808965356d6a02447d186107701fa24.zip
-fix post processor, expanded test suite to cover garbage before payload
Diffstat (limited to 'src/microhttpd/test_postprocessor.c')
-rw-r--r--src/microhttpd/test_postprocessor.c65
1 files changed, 51 insertions, 14 deletions
diff --git a/src/microhttpd/test_postprocessor.c b/src/microhttpd/test_postprocessor.c
index dd980506..ac3e2b91 100644
--- a/src/microhttpd/test_postprocessor.c
+++ b/src/microhttpd/test_postprocessor.c
@@ -1,10 +1,10 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 (C) 2007 Christian Grothoff 3 (C) 2007,2013 Christian Grothoff
4 4
5 libmicrohttpd is free software; you can redistribute it and/or modify 5 libmicrohttpd is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your 7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version. 8 option) any later version.
9 9
10 libmicrohttpd is distributed in the hope that it will be useful, but 10 libmicrohttpd is distributed in the hope that it will be useful, but
@@ -94,10 +94,12 @@ value_checker (void *cls,
94#if 0 94#if 0
95 fprintf (stderr, 95 fprintf (stderr,
96 "VC: `%s' `%s' `%s' `%s' `%.*s'\n", 96 "VC: `%s' `%s' `%s' `%s' `%.*s'\n",
97 key, filename, content_type, transfer_encoding, size, data); 97 key, filename, content_type, transfer_encoding,
98 (int) size,
99 data);
98#endif 100#endif
99 if ( (0 != off) && (0 == size) ) 101 if ( (0 != off) && (0 == size) )
100 return MHD_YES; 102 return MHD_YES;
101 if ((idx < 0) || 103 if ((idx < 0) ||
102 (want[idx] == NULL) || 104 (want[idx] == NULL) ||
103 (0 != strcmp (key, want[idx])) || 105 (0 != strcmp (key, want[idx])) ||
@@ -151,14 +153,53 @@ test_urlencoding ()
151 153
152 154
153static int 155static int
156test_multipart_garbage ()
157{
158 struct MHD_Connection connection;
159 struct MHD_HTTP_Header header;
160 struct MHD_PostProcessor *pp;
161 unsigned int want_off;
162 size_t size = strlen (FORM_DATA);
163 size_t splitpoint;
164 char xdata[size + 3];
165
166 /* fill in evil garbage at the beginning */
167 xdata[0] = '-';
168 xdata[1] = 'x';
169 xdata[2] = '\r';
170 memcpy (&xdata[3], FORM_DATA, size);
171 size += 3;
172
173 size = strlen (FORM_DATA);
174 for (splitpoint = 1; splitpoint < size; splitpoint++)
175 {
176 want_off = FORM_START;
177 memset (&connection, 0, sizeof (struct MHD_Connection));
178 memset (&header, 0, sizeof (struct MHD_HTTP_Header));
179 connection.headers_received = &header;
180 header.header = MHD_HTTP_HEADER_CONTENT_TYPE;
181 header.value =
182 MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA ", boundary=AaB03x";
183 header.kind = MHD_HEADER_KIND;
184 pp = MHD_create_post_processor (&connection,
185 1024, &value_checker, &want_off);
186 MHD_post_process (pp, xdata, splitpoint);
187 MHD_post_process (pp, &xdata[splitpoint], size - splitpoint);
188 MHD_destroy_post_processor (pp);
189 if (want_off != FORM_END)
190 return (int) splitpoint;
191 }
192 return 0;
193}
194
195
196static int
154test_multipart_splits () 197test_multipart_splits ()
155{ 198{
156 struct MHD_Connection connection; 199 struct MHD_Connection connection;
157 struct MHD_HTTP_Header header; 200 struct MHD_HTTP_Header header;
158 struct MHD_PostProcessor *pp; 201 struct MHD_PostProcessor *pp;
159 unsigned int want_off; 202 unsigned int want_off;
160 int i;
161 int delta;
162 size_t size; 203 size_t size;
163 size_t splitpoint; 204 size_t splitpoint;
164 205
@@ -175,13 +216,8 @@ test_multipart_splits ()
175 header.kind = MHD_HEADER_KIND; 216 header.kind = MHD_HEADER_KIND;
176 pp = MHD_create_post_processor (&connection, 217 pp = MHD_create_post_processor (&connection,
177 1024, &value_checker, &want_off); 218 1024, &value_checker, &want_off);
178 i = 0; 219 MHD_post_process (pp, FORM_DATA, splitpoint);
179 delta = splitpoint; 220 MHD_post_process (pp, &FORM_DATA[splitpoint], size - splitpoint);
180 MHD_post_process (pp, &FORM_DATA[i], delta);
181 i += delta;
182 delta = 1 + size - i;
183 MHD_post_process (pp, &FORM_DATA[i], delta);
184 i += delta;
185 MHD_destroy_post_processor (pp); 221 MHD_destroy_post_processor (pp);
186 if (want_off != FORM_END) 222 if (want_off != FORM_END)
187 return (int) splitpoint; 223 return (int) splitpoint;
@@ -301,8 +337,9 @@ main (int argc, char *const *argv)
301{ 337{
302 unsigned int errorCount = 0; 338 unsigned int errorCount = 0;
303 339
304 errorCount += test_urlencoding ();
305 errorCount += test_multipart_splits (); 340 errorCount += test_multipart_splits ();
341 errorCount += test_multipart_garbage ();
342 errorCount += test_urlencoding ();
306 errorCount += test_multipart (); 343 errorCount += test_multipart ();
307 errorCount += test_nested_multipart (); 344 errorCount += test_nested_multipart ();
308 errorCount += test_empty_value (); 345 errorCount += test_empty_value ();