aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLRN <lrn1986@gmail.com>2013-10-30 00:53:38 +0000
committerLRN <lrn1986@gmail.com>2013-10-30 00:53:38 +0000
commite524263be242e774d76377b04de9b033bd149d2e (patch)
treec11a2da916db3a85330240c47a898f32a6f38987
parent57b91a0399469dfccfa9c629d1f7173f87550858 (diff)
downloadlibmicrohttpd-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.h24
-rw-r--r--src/microhttpd/test_postprocessor.c41
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
74struct stat64 74struct _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
89typedef unsigned int sa_family_t; 89typedef unsigned int sa_family_t;
@@ -558,7 +558,7 @@ int _win_close(int fd);
558int _win_creat(const char *path, mode_t mode); 558int _win_creat(const char *path, mode_t mode);
559char *_win_ctime(const time_t *clock); 559char *_win_ctime(const time_t *clock);
560char *_win_ctime_r(const time_t *clock, char *buf); 560char *_win_ctime_r(const time_t *clock, char *buf);
561int _win_fstat(int handle, struct _stat *buffer); 561int _win_fstat(int handle, struct stat *buffer);
562int _win_ftruncate(int fildes, off_t length); 562int _win_ftruncate(int fildes, off_t length);
563int _win_truncate(const char *fname, int distance); 563int _win_truncate(const char *fname, int distance);
564int _win_kill(pid_t pid, int sig); 564int _win_kill(pid_t pid, int sig);
@@ -572,8 +572,8 @@ long _win_random(void);
572void _win_srandom(unsigned int seed); 572void _win_srandom(unsigned int seed);
573int _win_remove(const char *path); 573int _win_remove(const char *path);
574int _win_rename(const char *oldname, const char *newname); 574int _win_rename(const char *oldname, const char *newname);
575int _win_stat(const char *path, struct _stat *buffer); 575int _win_stat(const char *path, struct stat *buffer);
576int _win_stat64(const char *path, struct stat64 *buffer); 576int _win_stati64(const char *path, struct _stati64 *buffer);
577long _win_sysconf(int name); 577long _win_sysconf(int name);
578int _win_unlink(const char *filename); 578int _win_unlink(const char *filename);
579int _win_write(int fildes, const void *buf, size_t nbyte); 579int _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);
586int _win_msync(void *start, size_t length, int flags); 586int _win_msync(void *start, size_t length, int flags);
587int _win_munmap(void *start, size_t length); 587int _win_munmap(void *start, size_t length);
588int _win_lstat(const char *path, struct _stat *buf); 588int _win_lstat(const char *path, struct stat *buf);
589int _win_lstat64(const char *path, struct stat64 *buf); 589int _win_lstati64(const char *path, struct _stati64 *buf);
590int _win_readlink(const char *path, char *buf, size_t bufsize); 590int _win_readlink(const char *path, char *buf, size_t bufsize);
591int _win_accept(int s, struct sockaddr *addr, int *addrlen); 591int _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
153static int 153static int
154test_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
193static int
154test_multipart () 194test_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 ();