diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | src/daemon/Makefile.am | 7 | ||||
-rw-r--r-- | src/daemon/postprocessor.c | 23 | ||||
-rw-r--r-- | src/daemon/postprocessor_large_test.c | 109 |
4 files changed, 134 insertions, 9 deletions
@@ -1,3 +1,7 @@ | |||
1 | Fri May 23 16:54:41 MDT 2008 | ||
2 | Fixed issue with postprocessor not handling URI-encoded | ||
3 | values of more than 1024 bytes correctly. -CG | ||
4 | |||
1 | Mon May 5 09:18:29 MDT 2008 | 5 | Mon May 5 09:18:29 MDT 2008 |
2 | Fixed date header (was off by 1900 years). -JP | 6 | Fixed date header (was off by 1900 years). -JP |
3 | 7 | ||
diff --git a/src/daemon/Makefile.am b/src/daemon/Makefile.am index 3658ea23..4c8da52e 100644 --- a/src/daemon/Makefile.am +++ b/src/daemon/Makefile.am | |||
@@ -25,6 +25,7 @@ libmicrohttpd_la_SOURCES = \ | |||
25 | 25 | ||
26 | check_PROGRAMS = \ | 26 | check_PROGRAMS = \ |
27 | postprocessor_test \ | 27 | postprocessor_test \ |
28 | postprocessor_large_test \ | ||
28 | daemon_test | 29 | daemon_test |
29 | 30 | ||
30 | TESTS = $(check_PROGRAMS) | 31 | TESTS = $(check_PROGRAMS) |
@@ -38,3 +39,9 @@ postprocessor_test_SOURCES = \ | |||
38 | postprocessor_test.c | 39 | postprocessor_test.c |
39 | postprocessor_test_LDADD = \ | 40 | postprocessor_test_LDADD = \ |
40 | $(top_builddir)/src/daemon/libmicrohttpd.la | 41 | $(top_builddir)/src/daemon/libmicrohttpd.la |
42 | |||
43 | |||
44 | postprocessor_large_test_SOURCES = \ | ||
45 | postprocessor_large_test.c | ||
46 | postprocessor_large_test_LDADD = \ | ||
47 | $(top_builddir)/src/daemon/libmicrohttpd.la | ||
diff --git a/src/daemon/postprocessor.c b/src/daemon/postprocessor.c index 45713ed1..241bfcdd 100644 --- a/src/daemon/postprocessor.c +++ b/src/daemon/postprocessor.c | |||
@@ -361,9 +361,10 @@ post_process_urlencoded (struct MHD_PostProcessor *pp, | |||
361 | (post_data[amper + poff] != '\n') && | 361 | (post_data[amper + poff] != '\n') && |
362 | (post_data[amper + poff] != '\r')) | 362 | (post_data[amper + poff] != '\r')) |
363 | amper++; | 363 | amper++; |
364 | end_of_value_found = ( (post_data[amper + poff] == '&') || | 364 | end_of_value_found = ( (amper + poff < post_data_len) && |
365 | (post_data[amper + poff] == '\n') || | 365 | ( (post_data[amper + poff] == '&') || |
366 | (post_data[amper + poff] == '\r') ); | 366 | (post_data[amper + poff] == '\n') || |
367 | (post_data[amper + poff] == '\r') ) ); | ||
367 | /* compute delta, the maximum number of bytes that we will be able to | 368 | /* compute delta, the maximum number of bytes that we will be able to |
368 | process right now (either amper-limited of xbuf-size limited) */ | 369 | process right now (either amper-limited of xbuf-size limited) */ |
369 | delta = amper; | 370 | delta = amper; |
@@ -417,12 +418,16 @@ post_process_urlencoded (struct MHD_PostProcessor *pp, | |||
417 | if (end_of_value_found) | 418 | if (end_of_value_found) |
418 | { | 419 | { |
419 | /* we found the end of the value! */ | 420 | /* we found the end of the value! */ |
420 | pp->state = PP_Init; | 421 | if ((post_data[poff] == '\n') || |
421 | poff++; /* skip '&' or new-lines */ | 422 | (post_data[poff] == '\r')) |
422 | 423 | { | |
423 | if ((post_data[poff - 1] == '\n') || | 424 | pp->state = PP_ExpectNewLine; |
424 | (post_data[poff - 1] == '\r')) | 425 | } |
425 | pp->state = PP_ExpectNewLine; | 426 | else |
427 | { | ||
428 | poff++; /* skip '&' */ | ||
429 | pp->state = PP_Init; | ||
430 | } | ||
426 | } | 431 | } |
427 | break; | 432 | break; |
428 | case PP_ExpectNewLine: | 433 | case PP_ExpectNewLine: |
diff --git a/src/daemon/postprocessor_large_test.c b/src/daemon/postprocessor_large_test.c new file mode 100644 index 00000000..549f606e --- /dev/null +++ b/src/daemon/postprocessor_large_test.c | |||
@@ -0,0 +1,109 @@ | |||
1 | /* | ||
2 | This file is part of libmicrohttpd | ||
3 | (C) 2008 Christian Grothoff | ||
4 | |||
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 | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | libmicrohttpd is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with libmicrohttpd; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file postprocessor_large_test.c | ||
23 | * @brief Testcase with very large input for postprocessor | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #include "config.h" | ||
28 | #include "microhttpd.h" | ||
29 | #include "internal.h" | ||
30 | #include <stdlib.h> | ||
31 | #include <string.h> | ||
32 | #include <stdio.h> | ||
33 | |||
34 | #ifndef WINDOWS | ||
35 | #include <unistd.h> | ||
36 | #endif | ||
37 | |||
38 | static int | ||
39 | value_checker (void *cls, | ||
40 | enum MHD_ValueKind kind, | ||
41 | const char *key, | ||
42 | const char *filename, | ||
43 | const char *content_type, | ||
44 | const char *transfer_encoding, | ||
45 | const char *data, size_t off, size_t size) | ||
46 | { | ||
47 | unsigned int *pos = cls; | ||
48 | #if 0 | ||
49 | fprintf (stderr, | ||
50 | "VC: %u %u `%s' `%s' `%s' `%s' `%.*s'\n", | ||
51 | off, size, | ||
52 | key, filename, content_type, transfer_encoding, size, data); | ||
53 | #endif | ||
54 | if (size == 0) | ||
55 | return MHD_YES; | ||
56 | *pos += size; | ||
57 | return MHD_YES; | ||
58 | |||
59 | } | ||
60 | |||
61 | |||
62 | static int | ||
63 | test_simple_large () | ||
64 | { | ||
65 | struct MHD_Connection connection; | ||
66 | struct MHD_HTTP_Header header; | ||
67 | struct MHD_PostProcessor *pp; | ||
68 | int i; | ||
69 | int delta; | ||
70 | size_t size; | ||
71 | char data[102400]; | ||
72 | unsigned int pos; | ||
73 | |||
74 | pos = 0; | ||
75 | memset (data, 'A', sizeof(data)); | ||
76 | memcpy (data, "key=", 4); | ||
77 | data[sizeof(data)-1] = '\0'; | ||
78 | memset (&connection, 0, sizeof (struct MHD_Connection)); | ||
79 | memset (&header, 0, sizeof (struct MHD_HTTP_Header)); | ||
80 | connection.headers_received = &header; | ||
81 | header.header = MHD_HTTP_HEADER_CONTENT_TYPE; | ||
82 | header.value = MHD_HTTP_POST_ENCODING_FORM_URLENCODED; | ||
83 | header.kind = MHD_HEADER_KIND; | ||
84 | pp = MHD_create_post_processor (&connection, | ||
85 | 1024, &value_checker, &pos); | ||
86 | i = 0; | ||
87 | size = strlen (data); | ||
88 | while (i < size) | ||
89 | { | ||
90 | delta = 1 + random () % (size - i); | ||
91 | MHD_post_process (pp, &data[i], delta); | ||
92 | i += delta; | ||
93 | } | ||
94 | MHD_destroy_post_processor (pp); | ||
95 | if (pos != sizeof(data) - 5) /* minus 0-termination and 'key=' */ | ||
96 | return 1; | ||
97 | return 0; | ||
98 | } | ||
99 | |||
100 | int | ||
101 | main (int argc, char *const *argv) | ||
102 | { | ||
103 | unsigned int errorCount = 0; | ||
104 | |||
105 | errorCount += test_simple_large (); | ||
106 | if (errorCount != 0) | ||
107 | fprintf (stderr, "Error (code: %u)\n", errorCount); | ||
108 | return errorCount != 0; /* 0 == pass */ | ||
109 | } | ||