[Oisf-devel] [PATCH 1/7] Fix some Packet initialisation.

Eric Leblond eric at regit.org
Mon Jan 31 22:45:35 UTC 2011


This patch fixes Packet initialisation. In some place the pkt field
was not set after a memset used to zero the structure and this could
lead to some problems.
---
 src/app-layer-detect-proto.c |    1 +
 src/util-mpm-b2g-cuda.c      |    6 +++++-
 src/util-unittest-helper.c   |    3 +++
 3 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/src/app-layer-detect-proto.c b/src/app-layer-detect-proto.c
index e904c70..b404c5b 100644
--- a/src/app-layer-detect-proto.c
+++ b/src/app-layer-detect-proto.c
@@ -478,6 +478,7 @@ uint16_t AppLayerDetectGetProto(AlpProtoDetectCtx *ctx, AlpProtoDetectThreadCtx
     if (p == NULL)
         goto end;
     memset(p, 0, SIZE_OF_PACKET);
+    p->pkt = (uint8_t *)(p + 1);
 
     p->cuda_done = 0;
     p->cuda_free_packet = 1;
diff --git a/src/util-mpm-b2g-cuda.c b/src/util-mpm-b2g-cuda.c
index 5932446..f8831f2 100644
--- a/src/util-mpm-b2g-cuda.c
+++ b/src/util-mpm-b2g-cuda.c
@@ -2757,7 +2757,7 @@ static int B2gCudaTest01(void)
 
     Packet *p = SCMalloc(SIZE_OF_PACKET);
     if (p == NULL)
-        return 0;
+        goto end;
     memset(p, 0, SIZE_OF_PACKET);
     p->pkt = (uint8_t *)(p + 1);
     pb->packets_address_buffer[0] = p;
@@ -2902,6 +2902,7 @@ static int B2gCudaTest02(void)
             exit(EXIT_FAILURE);
         }
         memset(p[i], 0, SIZE_OF_PACKET);
+        p[i]->pkt = (uint8_t *)(p[i] + 1);
         DecodeEthernet(&tv, &dtv, p[i], raw_eth, sizeof(raw_eth), NULL);
     }
 
@@ -3121,6 +3122,7 @@ static int B2gCudaTest03(void)
             exit(EXIT_FAILURE);
         }
         memset(p[i], 0, SIZE_OF_PACKET);
+        p[i]->pkt = (uint8_t *)(p[i] + 1);
         DecodeEthernet(&tv, &dtv, p[i], raw_eth, sizeof(raw_eth), NULL);
     }
 
@@ -3443,6 +3445,7 @@ static int B2gCudaTest04(void)
             exit(EXIT_FAILURE);
         }
         memset(p[i], 0, sizeof(Packet));
+        p[i]->pkt = (uint8_t *)(p[i] + 1);
         DecodeEthernet(&tv, &dtv, p[i], raw_eth, sizeof(raw_eth), NULL);
     }
 
@@ -3786,6 +3789,7 @@ static int B2gCudaTest05(void)
             exit(EXIT_FAILURE);
         }
         memset(p[i], 0, sizeof(Packet));
+        p[i]->pkt = (uint8_t *)(p[i] + 1);
         DecodeEthernet(&tv, &dtv, p[i], raw_eth, sizeof(raw_eth), NULL);
     }
 
diff --git a/src/util-unittest-helper.c b/src/util-unittest-helper.c
index 1c6286f..f7fbe01 100644
--- a/src/util-unittest-helper.c
+++ b/src/util-unittest-helper.c
@@ -66,6 +66,7 @@ Packet *UTHBuildPacketIPV6Real(uint8_t *payload, uint16_t payload_len,
     if (p == NULL)
         return NULL;
     memset(p, 0, SIZE_OF_PACKET);
+    p->pkt = (uint8_t *)(p + 1);
 
     TimeSet(&p->ts);
 
@@ -259,6 +260,7 @@ Packet **UTHBuildPacketArrayFromEth(uint8_t *raw_eth[], int *pktsize, int numpkt
             return NULL;
         }
         memset(p[i], 0, SIZE_OF_PACKET);
+        p[i]->pkt = (uint8_t *)(p[i] + 1);
         DecodeEthernet(&th_v, &dtv, p[i], raw_eth[i], pktsize[i], NULL);
     }
     return p;
@@ -280,6 +282,7 @@ Packet *UTHBuildPacketFromEth(uint8_t *raw_eth, uint16_t pktsize) {
     if (p == NULL)
         return NULL;
     memset(p, 0, SIZE_OF_PACKET);
+    p->pkt = (uint8_t *)(p + 1);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&th_v, 0, sizeof(th_v));
 
-- 
1.7.1




More information about the Oisf-devel mailing list