]> granicus.if.org Git - apache/commitdiff
mod_lua: Use binary strstr for finding endpoints of a multipart object. (How did...
authorDaniel Gruno <humbedooh@apache.org>
Sun, 20 Apr 2014 13:58:13 +0000 (13:58 +0000)
committerDaniel Gruno <humbedooh@apache.org>
Sun, 20 Apr 2014 13:58:13 +0000 (13:58 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1588761 13f79535-47bb-0310-9956-ffa450edef68

modules/lua/lua_request.c

index fd8e208cc28ce58788a096e4f91ab526b0c6ce02..f2de2751ef189b8e538097af31aed3433b2e5b43 100644 (file)
@@ -317,6 +317,20 @@ static int req_parseargs(lua_State *L)
     return 2;                   /* [table<string, string>, table<string, array<string>>] */
 }
 
+/* ap_lua_binstrstr: Binary strstr function for uploaded data with NULL bytes */
+char* ap_lua_binstrstr (const char * haystack, size_t hsize, const char* needle, size_t nsize)
+{
+    if (haystack == NULL) return NULL;
+    if (needle == NULL) return NULL;
+    if (hsize < nsize) return NULL;
+    for (size_t p = 0; p <= (hsize - nsize); ++p) {
+        if (memcmp(haystack + p, needle, nsize) == 0) {
+            return (char*) (haystack + p);
+        }
+    }
+    return NULL;
+} 
+
 /* r:parsebody(): Parses regular (url-enocded) or multipart POST data and returns two tables*/
 static int req_parsebody(lua_State *L)
 {
@@ -348,15 +362,15 @@ static int req_parsebody(lua_State *L)
         for
         (
             start = strstr((char *) data, multipart);
-            start != start + size;
+            start != NULL;
             start = end
         ) {
             i++;
             if (i == POST_MAX_VARS) break;
-            end = strstr((char *) (start + 1), multipart);
-            if (!end) end = start + size;
             crlf = strstr((char *) start, "\r\n\r\n");
             if (!crlf) break;
+            end = ap_lua_binstrstr(crlf, (size - (crlf - data)), multipart, len);
+            if (end == NULL) break;
             key = (char *) apr_pcalloc(r->pool, 256);
             filename = (char *) apr_pcalloc(r->pool, 256);
             vlen = end - crlf - 8;