]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
htp: make htp state handling function more robust
authorVictor Julien <victor@inliniac.net>
Thu, 19 Jun 2014 08:36:36 +0000 (10:36 +0200)
committerVictor Julien <victor@inliniac.net>
Sat, 21 Jun 2014 09:07:19 +0000 (11:07 +0200)
Also, fix wrong cast that worked only by luck.

src/app-layer-htp.c

index 125ce3e1e1a50fb2e6ed2a38273c6f903a6117d3..c91cfbd0ebf1aedc6cf4605597ec9e44e0e4fc46 100644 (file)
@@ -2571,12 +2571,22 @@ static int HTPStateGetAlstateProgress(void *tx, uint8_t direction)
 
 static uint64_t HTPStateGetTxCnt(void *alstate)
 {
-    return (uint64_t)htp_list_size(((htp_tx_t *)alstate)->conn->transactions);
+    HtpState *http_state = (HtpState *)alstate;
+
+    if (http_state != NULL && http_state->conn != NULL)
+        return (uint64_t)htp_list_size(http_state->conn->transactions);
+    else
+        return 0ULL;
 }
 
 static void *HTPStateGetTx(void *alstate, uint64_t tx_id)
 {
-    return htp_list_get(((htp_tx_t *)alstate)->conn->transactions, tx_id);
+    HtpState *http_state = (HtpState *)alstate;
+
+    if (http_state != NULL && http_state->conn != NULL)
+        return htp_list_get(http_state->conn->transactions, tx_id);
+    else
+        return NULL;
 }
 
 static int HTPStateGetAlstateProgressCompletionStatus(uint8_t direction)