]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Improve http filename parsing.
authorVictor Julien <victor@inliniac.net>
Fri, 2 Mar 2012 10:05:49 +0000 (11:05 +0100)
committerVictor Julien <victor@inliniac.net>
Fri, 2 Mar 2012 10:05:49 +0000 (11:05 +0100)
src/app-layer-htp.c
src/util-file.c

index 35e802fb78ab2522983094f0a18a0ae73ac7248b..89e0fd7b89b07b44ba143e1f432092ea3e5e1d27 100644 (file)
@@ -1559,15 +1559,17 @@ static int HtpRequestBodyHandlePOST(HtpState *hstate, HtpTxUserData *htud,
             filename_len = bstr_len(tx->parsed_uri->path);
         }
 
-        result = HTPFileOpen(hstate, filename, filename_len, data, data_len,
-                hstate->transaction_cnt, STREAM_TOSERVER);
-        if (result == -1) {
-            goto end;
-        } else if (result == -2) {
-            htud->flags |= HTP_DONTSTORE;
-        } else {
-            htud->flags |= HTP_FILENAME_SET;
-            htud->flags &= ~HTP_DONTSTORE;
+        if (filename != NULL) {
+            result = HTPFileOpen(hstate, filename, filename_len, data, data_len,
+                    hstate->transaction_cnt, STREAM_TOSERVER);
+            if (result == -1) {
+                goto end;
+            } else if (result == -2) {
+                htud->flags |= HTP_DONTSTORE;
+            } else {
+                htud->flags |= HTP_FILENAME_SET;
+                htud->flags &= ~HTP_DONTSTORE;
+            }
         }
     }
     else
@@ -1610,15 +1612,17 @@ static int HtpRequestBodyHandlePUT(HtpState *hstate, HtpTxUserData *htud,
             filename_len = bstr_len(tx->parsed_uri->path);
         }
 
-        result = HTPFileOpen(hstate, filename, filename_len, data, data_len,
-                hstate->transaction_cnt, STREAM_TOSERVER);
-        if (result == -1) {
-            goto end;
-        } else if (result == -2) {
-            htud->flags |= HTP_DONTSTORE;
-        } else {
-            htud->flags |= HTP_FILENAME_SET;
-            htud->flags &= ~HTP_DONTSTORE;
+        if (filename != NULL) {
+            result = HTPFileOpen(hstate, filename, filename_len, data, data_len,
+                    hstate->transaction_cnt, STREAM_TOSERVER);
+            if (result == -1) {
+                goto end;
+            } else if (result == -2) {
+                htud->flags |= HTP_DONTSTORE;
+            } else {
+                htud->flags |= HTP_FILENAME_SET;
+                htud->flags &= ~HTP_DONTSTORE;
+            }
         }
     }
     else
@@ -1674,16 +1678,18 @@ int HtpResponseBodyHandle(HtpState *hstate, HtpTxUserData *htud,
             }
         }
 
-        result = HTPFileOpen(hstate, filename, filename_len,
+        if (filename != NULL) {
+            result = HTPFileOpen(hstate, filename, filename_len,
                     data, data_len, hstate->transaction_cnt, STREAM_TOCLIENT);
-        SCLogDebug("result %d", result);
-        if (result == -1) {
-            goto end;
-        } else if (result == -2) {
-            htud->flags |= HTP_DONTSTORE;
-        } else {
-            htud->flags |= HTP_FILENAME_SET;
-            htud->flags &= ~HTP_DONTSTORE;
+            SCLogDebug("result %d", result);
+            if (result == -1) {
+                goto end;
+            } else if (result == -2) {
+                htud->flags |= HTP_DONTSTORE;
+            } else {
+                htud->flags |= HTP_FILENAME_SET;
+                htud->flags &= ~HTP_DONTSTORE;
+            }
         }
     }
     else
index d32e520c60741c7676b354e7616beadedb01d9c7..ac66064ce5e99c9249243aa9cf512904bc2df195 100644 (file)
@@ -332,7 +332,7 @@ static void FileFree(File *ff) {
 }
 
 void FileContainerAdd(FileContainer *ffc, File *ff) {
-    if (ffc->head == NULL) {
+    if (ffc->head == NULL || ffc->tail == NULL) {
         ffc->head = ffc->tail = ff;
     } else {
         ffc->tail->next = ff;
@@ -358,7 +358,8 @@ int FileStore(File *ff) {
  */
 int FileSetTx(File *ff, uint16_t txid) {
     SCLogDebug("ff %p txid %"PRIu16, ff, txid);
-    ff->txid = txid;
+    if (ff != NULL)
+        ff->txid = txid;
     SCReturnInt(0);
 }