]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
af-packet/v2: use proper type for ring
authorVictor Julien <vjulien@oisf.net>
Wed, 27 Apr 2022 09:32:22 +0000 (11:32 +0200)
committerVictor Julien <vjulien@oisf.net>
Wed, 4 May 2022 16:56:47 +0000 (18:56 +0200)
cppcheck:

src/source-af-packet.c:1762:19: warning: Size of pointer 'v2' used instead of size of its data. This is likely to lead to a buffer overflow. You probably intend to write 'sizeof(*v2)'. [pointerSize]
        ptv->ring.v2 = SCMalloc(ptv->req.v2.tp_frame_nr * sizeof (union thdr *));
                  ^
src/source-af-packet.c:1767:26: warning: Size of pointer 'v2' used instead of size of its data. This is likely to lead to a buffer overflow. You probably intend to write 'sizeof(*v2)'. [pointerSize]
        memset(ptv->ring.v2, 0, ptv->req.v2.tp_frame_nr * sizeof (union thdr *));
                         ^

scan-build:

CC       source-af-packet.o
source-af-packet.c:1762:24: warning: Result of 'malloc' is converted to a pointer of type 'char', which is incompatible with sizeof operand type 'union thdr *' [unix.MallocSizeof]
        ptv->ring.v2 = SCMalloc(ptv->req.v2.tp_frame_nr * sizeof (union thdr *));
                       ^~~~~~~~                           ~~~~~~~~~~~~~~~~~~~~~
./util-mem.h:35:18: note: expanded from macro 'SCMalloc'
                 ^~~~~~
1 warning generated.

Bug: #5291.
(cherry picked from commit fedced209dc25443ec5eee22bfab6c99f9f652ab)

src/source-af-packet.c

index d702c4430e8aa28a56905076984b70173a904e36..9a2e283c500afcd6c72c626036b6e6c6fdcbb7ce 100644 (file)
@@ -261,7 +261,7 @@ static int AFPXDPBypassCallback(Packet *p);
 typedef struct AFPThreadVars_
 {
     union AFPRing {
-        char *v2;
+        union thdr **v2;
         struct iovec *v3;
     } ring;
 
@@ -2010,12 +2010,11 @@ static int AFPSetupRing(AFPThreadVars *ptv, char *devname)
     } else {
 #endif
         /* allocate a ring for each frame header pointer*/
-        ptv->ring.v2 = SCMalloc(ptv->req.v2.tp_frame_nr * sizeof (union thdr *));
+        ptv->ring.v2 = SCCalloc(ptv->req.v2.tp_frame_nr, sizeof(union thdr *));
         if (ptv->ring.v2 == NULL) {
             SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate frame buf");
             goto postmmap_err;
         }
-        memset(ptv->ring.v2, 0, ptv->req.v2.tp_frame_nr * sizeof (union thdr *));
         /* fill the header ring with proper frame ptr*/
         ptv->frame_offset = 0;
         for (i = 0; i < ptv->req.v2.tp_block_nr; ++i) {