From: Victor Julien Date: Fri, 2 Mar 2012 10:05:49 +0000 (+0100) Subject: Improve http filename parsing. X-Git-Tag: suricata-1.3beta1~136 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3935a2af28dabdf0c391090e0b3d37c64dfbfbc;p=thirdparty%2Fsuricata.git Improve http filename parsing. --- diff --git a/src/app-layer-htp.c b/src/app-layer-htp.c index 35e802fb78..89e0fd7b89 100644 --- a/src/app-layer-htp.c +++ b/src/app-layer-htp.c @@ -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 diff --git a/src/util-file.c b/src/util-file.c index d32e520c60..ac66064ce5 100644 --- a/src/util-file.c +++ b/src/util-file.c @@ -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); }