diff options
author | LRN <lrn1986@gmail.com> | 2013-10-30 00:53:38 +0000 |
---|---|---|
committer | LRN <lrn1986@gmail.com> | 2013-10-30 00:53:38 +0000 |
commit | e524263be242e774d76377b04de9b033bd149d2e (patch) | |
tree | c11a2da916db3a85330240c47a898f32a6f38987 | |
parent | 57b91a0399469dfccfa9c629d1f7173f87550858 (diff) | |
download | libmicrohttpd-e524263be242e774d76377b04de9b033bd149d2e.tar.gz libmicrohttpd-e524263be242e774d76377b04de9b033bd149d2e.zip |
Add a variant of multipart preprocessor test that splits data in two parts
before feeding it to the preprocessor, trying all possible points where data
can be split. Prior to r30427 this test would have crashed only if data is
split at the very beginning (< 11). After r30427 this test crashes every time
the data is split somewhere around the boundary.
At least that is the case on W32.
-rw-r--r-- | src/include/plibc/plibc.h | 24 | ||||
-rw-r--r-- | src/microhttpd/test_postprocessor.c | 41 |
2 files changed, 54 insertions, 11 deletions
diff --git a/src/include/plibc/plibc.h b/src/include/plibc/plibc.h index ca293fde..6ee3fa5b 100644 --- a/src/include/plibc/plibc.h +++ b/src/include/plibc/plibc.h | |||
@@ -71,7 +71,7 @@ extern "C" { | |||
71 | #define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + \ | 71 | #define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + \ |
72 | (double)((x).LowPart)) | 72 | (double)((x).LowPart)) |
73 | #ifndef __MINGW64_VERSION_MAJOR | 73 | #ifndef __MINGW64_VERSION_MAJOR |
74 | struct stat64 | 74 | struct _stati64 |
75 | { | 75 | { |
76 | _dev_t st_dev; | 76 | _dev_t st_dev; |
77 | _ino_t st_ino; | 77 | _ino_t st_ino; |
@@ -81,9 +81,9 @@ struct stat64 | |||
81 | short st_gid; | 81 | short st_gid; |
82 | _dev_t st_rdev; | 82 | _dev_t st_rdev; |
83 | __int64 st_size; | 83 | __int64 st_size; |
84 | __time64_t st_atime; | 84 | time_t st_atime; |
85 | __time64_t st_mtime; | 85 | time_t st_mtime; |
86 | __time64_t st_ctime; | 86 | time_t st_ctime; |
87 | }; | 87 | }; |
88 | #endif | 88 | #endif |
89 | typedef unsigned int sa_family_t; | 89 | typedef unsigned int sa_family_t; |
@@ -558,7 +558,7 @@ int _win_close(int fd); | |||
558 | int _win_creat(const char *path, mode_t mode); | 558 | int _win_creat(const char *path, mode_t mode); |
559 | char *_win_ctime(const time_t *clock); | 559 | char *_win_ctime(const time_t *clock); |
560 | char *_win_ctime_r(const time_t *clock, char *buf); | 560 | char *_win_ctime_r(const time_t *clock, char *buf); |
561 | int _win_fstat(int handle, struct _stat *buffer); | 561 | int _win_fstat(int handle, struct stat *buffer); |
562 | int _win_ftruncate(int fildes, off_t length); | 562 | int _win_ftruncate(int fildes, off_t length); |
563 | int _win_truncate(const char *fname, int distance); | 563 | int _win_truncate(const char *fname, int distance); |
564 | int _win_kill(pid_t pid, int sig); | 564 | int _win_kill(pid_t pid, int sig); |
@@ -572,8 +572,8 @@ long _win_random(void); | |||
572 | void _win_srandom(unsigned int seed); | 572 | void _win_srandom(unsigned int seed); |
573 | int _win_remove(const char *path); | 573 | int _win_remove(const char *path); |
574 | int _win_rename(const char *oldname, const char *newname); | 574 | int _win_rename(const char *oldname, const char *newname); |
575 | int _win_stat(const char *path, struct _stat *buffer); | 575 | int _win_stat(const char *path, struct stat *buffer); |
576 | int _win_stat64(const char *path, struct stat64 *buffer); | 576 | int _win_stati64(const char *path, struct _stati64 *buffer); |
577 | long _win_sysconf(int name); | 577 | long _win_sysconf(int name); |
578 | int _win_unlink(const char *filename); | 578 | int _win_unlink(const char *filename); |
579 | int _win_write(int fildes, const void *buf, size_t nbyte); | 579 | int _win_write(int fildes, const void *buf, size_t nbyte); |
@@ -585,8 +585,8 @@ void *_win_mmap(void *start, size_t len, int access, int flags, int fd, | |||
585 | unsigned long long offset); | 585 | unsigned long long offset); |
586 | int _win_msync(void *start, size_t length, int flags); | 586 | int _win_msync(void *start, size_t length, int flags); |
587 | int _win_munmap(void *start, size_t length); | 587 | int _win_munmap(void *start, size_t length); |
588 | int _win_lstat(const char *path, struct _stat *buf); | 588 | int _win_lstat(const char *path, struct stat *buf); |
589 | int _win_lstat64(const char *path, struct stat64 *buf); | 589 | int _win_lstati64(const char *path, struct _stati64 *buf); |
590 | int _win_readlink(const char *path, char *buf, size_t bufsize); | 590 | int _win_readlink(const char *path, char *buf, size_t bufsize); |
591 | int _win_accept(int s, struct sockaddr *addr, int *addrlen); | 591 | int _win_accept(int s, struct sockaddr *addr, int *addrlen); |
592 | 592 | ||
@@ -745,6 +745,7 @@ char *strcasestr(const char *haystack_start, const char *needle_start); | |||
745 | #define TDESTROY(r, f) tdestroy(r, f) | 745 | #define TDESTROY(r, f) tdestroy(r, f) |
746 | #define LFIND(k, b, n, s, c) lfind(k, b, n, s, c) | 746 | #define LFIND(k, b, n, s, c) lfind(k, b, n, s, c) |
747 | #define LSEARCH(k, b, n, s, c) lsearch(k, b, n, s, c) | 747 | #define LSEARCH(k, b, n, s, c) lsearch(k, b, n, s, c) |
748 | #define STRUCT_STAT64 struct stat64 | ||
748 | #else | 749 | #else |
749 | #define DIR_SEPARATOR '\\' | 750 | #define DIR_SEPARATOR '\\' |
750 | #define DIR_SEPARATOR_STR "\\" | 751 | #define DIR_SEPARATOR_STR "\\" |
@@ -780,7 +781,7 @@ char *strcasestr(const char *haystack_start, const char *needle_start); | |||
780 | #define REMOVE(p) _win_remove(p) | 781 | #define REMOVE(p) _win_remove(p) |
781 | #define RENAME(o, n) _win_rename(o, n) | 782 | #define RENAME(o, n) _win_rename(o, n) |
782 | #define STAT(p, b) _win_stat(p, b) | 783 | #define STAT(p, b) _win_stat(p, b) |
783 | #define STAT64(p, b) _win_stat64(p, b) | 784 | #define STAT64(p, b) _win_stati64(p, b) |
784 | #define SYSCONF(n) _win_sysconf(n) | 785 | #define SYSCONF(n) _win_sysconf(n) |
785 | #define UNLINK(f) _win_unlink(f) | 786 | #define UNLINK(f) _win_unlink(f) |
786 | #define WRITE(f, b, n) _win_write(f, b, n) | 787 | #define WRITE(f, b, n) _win_write(f, b, n) |
@@ -795,7 +796,7 @@ char *strcasestr(const char *haystack_start, const char *needle_start); | |||
795 | #define STRERROR(i) _win_strerror(i) | 796 | #define STRERROR(i) _win_strerror(i) |
796 | #define READLINK(p, b, s) _win_readlink(p, b, s) | 797 | #define READLINK(p, b, s) _win_readlink(p, b, s) |
797 | #define LSTAT(p, b) _win_lstat(p, b) | 798 | #define LSTAT(p, b) _win_lstat(p, b) |
798 | #define LSTAT64(p, b) _win_lstat64(p, b) | 799 | #define LSTAT64(p, b) _win_lstati64(p, b) |
799 | #define PRINTF printf | 800 | #define PRINTF printf |
800 | #define FPRINTF fprintf | 801 | #define FPRINTF fprintf |
801 | #define VPRINTF(f, a) vprintf(f, a) | 802 | #define VPRINTF(f, a) vprintf(f, a) |
@@ -845,6 +846,7 @@ char *strcasestr(const char *haystack_start, const char *needle_start); | |||
845 | #define TDESTROY(r, f) _win_tdestroy(r, f) | 846 | #define TDESTROY(r, f) _win_tdestroy(r, f) |
846 | #define LFIND(k, b, n, s, c) _win_lfind(k, b, n, s, c) | 847 | #define LFIND(k, b, n, s, c) _win_lfind(k, b, n, s, c) |
847 | #define LSEARCH(k, b, n, s, c) _win_lsearch(k, b, n, s, c) | 848 | #define LSEARCH(k, b, n, s, c) _win_lsearch(k, b, n, s, c) |
849 | #define STRUCT_STAT64 struct _stati64 | ||
848 | #endif | 850 | #endif |
849 | 851 | ||
850 | /* search.h */ | 852 | /* search.h */ |
diff --git a/src/microhttpd/test_postprocessor.c b/src/microhttpd/test_postprocessor.c index eb412b72..dd980506 100644 --- a/src/microhttpd/test_postprocessor.c +++ b/src/microhttpd/test_postprocessor.c | |||
@@ -151,6 +151,46 @@ test_urlencoding () | |||
151 | 151 | ||
152 | 152 | ||
153 | static int | 153 | static int |
154 | test_multipart_splits () | ||
155 | { | ||
156 | struct MHD_Connection connection; | ||
157 | struct MHD_HTTP_Header header; | ||
158 | struct MHD_PostProcessor *pp; | ||
159 | unsigned int want_off; | ||
160 | int i; | ||
161 | int delta; | ||
162 | size_t size; | ||
163 | size_t splitpoint; | ||
164 | |||
165 | size = strlen (FORM_DATA); | ||
166 | for (splitpoint = 1; splitpoint < size; splitpoint++) | ||
167 | { | ||
168 | want_off = FORM_START; | ||
169 | memset (&connection, 0, sizeof (struct MHD_Connection)); | ||
170 | memset (&header, 0, sizeof (struct MHD_HTTP_Header)); | ||
171 | connection.headers_received = &header; | ||
172 | header.header = MHD_HTTP_HEADER_CONTENT_TYPE; | ||
173 | header.value = | ||
174 | MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA ", boundary=AaB03x"; | ||
175 | header.kind = MHD_HEADER_KIND; | ||
176 | pp = MHD_create_post_processor (&connection, | ||
177 | 1024, &value_checker, &want_off); | ||
178 | i = 0; | ||
179 | delta = 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); | ||
186 | if (want_off != FORM_END) | ||
187 | return (int) splitpoint; | ||
188 | } | ||
189 | return 0; | ||
190 | } | ||
191 | |||
192 | |||
193 | static int | ||
154 | test_multipart () | 194 | test_multipart () |
155 | { | 195 | { |
156 | struct MHD_Connection connection; | 196 | struct MHD_Connection connection; |
@@ -262,6 +302,7 @@ main (int argc, char *const *argv) | |||
262 | unsigned int errorCount = 0; | 302 | unsigned int errorCount = 0; |
263 | 303 | ||
264 | errorCount += test_urlencoding (); | 304 | errorCount += test_urlencoding (); |
305 | errorCount += test_multipart_splits (); | ||
265 | errorCount += test_multipart (); | 306 | errorCount += test_multipart (); |
266 | errorCount += test_nested_multipart (); | 307 | errorCount += test_nested_multipart (); |
267 | errorCount += test_empty_value (); | 308 | errorCount += test_empty_value (); |