]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
flow: fix unlikely issue with int handling
authorVictor Julien <victor@inliniac.net>
Tue, 14 Jul 2020 08:48:57 +0000 (10:48 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 14 Jul 2020 08:49:00 +0000 (10:49 +0200)
Thanks for reporting this magenbluten PR 4575.

src/tmqh-flow.c

index 4ddb4193db161317b637d69e4a3d01717279dca9..a02c930f101f0ff6fbac508fd5f55a1add0b05b6 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2007-2013 Open Information Security Foundation
+/* Copyright (C) 2007-2020 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
@@ -220,8 +220,7 @@ void TmqhOutputFlowFreeCtx(void *ctx)
 
 void TmqhOutputFlowHash(ThreadVars *tv, Packet *p)
 {
-    int16_t qid = 0;
-
+    uint32_t qid;
     TmqhFlowCtx *ctx = (TmqhFlowCtx *)tv->outctx;
 
     if (p->flags & PKT_WANTS_FLOW) {
@@ -251,24 +250,19 @@ void TmqhOutputFlowHash(ThreadVars *tv, Packet *p)
  */
 void TmqhOutputFlowIPPair(ThreadVars *tv, Packet *p)
 {
-    int16_t qid = 0;
     uint32_t addr_hash = 0;
-    int i;
 
     TmqhFlowCtx *ctx = (TmqhFlowCtx *)tv->outctx;
 
     if (p->src.family == AF_INET6) {
-        for (i = 0; i < 4; i++) {
+        for (int i = 0; i < 4; i++) {
             addr_hash += p->src.addr_data32[i] + p->dst.addr_data32[i];
         }
     } else {
         addr_hash = p->src.addr_data32[0] + p->dst.addr_data32[0];
     }
 
-    /* we don't have to worry about possible overflow, since
-     * ctx->size will be lesser than 2 ** 31 for sure */
-    qid = addr_hash % ctx->size;
-
+    uint32_t qid = addr_hash % ctx->size;
     PacketQueue *q = ctx->queues[qid].q;
     SCMutexLock(&q->mutex_q);
     PacketEnqueue(q, p);