9b816c
From fdf4c18b1f2c17eddc871d4a593240a59dd0682f Mon Sep 17 00:00:00 2001
9b816c
From: Adrian Reber <areber@redhat.com>
9b816c
Date: Wed, 14 Apr 2021 09:21:50 +0200
9b816c
Subject: [PATCH 1/3] libnet_port_list.c: fix gcc -fanalyzer warning
9b816c
MIME-Version: 1.0
9b816c
Content-Type: text/plain; charset=UTF-8
9b816c
Content-Transfer-Encoding: 8bit
9b816c
9b816c
This fixes:
9b816c
9b816c
libnet_port_list.c:99:8: warning: leak of ‘_8’ [CWE-401] [-Wanalyzer-malloc-leak]
9b816c
   99 |     if (!all_lists)
9b816c
      |        ^
9b816c
  ‘libnet_plist_chain_new’: events 1-3
9b816c
    |
9b816c
    |   48 |     if (l == NULL)
9b816c
    |      |        ^
9b816c
    |      |        |
9b816c
    |      |        (1) following ‘false’ branch (when ‘l_70(D)’ is non-NULL)...
9b816c
    |......
9b816c
    |   53 |     if (token_list == NULL)
9b816c
    |      |     ~~ ~
9b816c
    |      |     |  |
9b816c
    |      |     |  (3) following ‘false’ branch (when ‘token_list_71(D)’ is non-NULL)...
9b816c
    |      |     (2) ...to here
9b816c
    |
9b816c
  ‘libnet_plist_chain_new’: event 4
9b816c
    |
9b816c
    |cc1:
9b816c
    | (4): ...to here
9b816c
    |
9b816c
  ‘libnet_plist_chain_new’: events 5-9
9b816c
    |
9b816c
    |   83 |     *plist = malloc(sizeof (libnet_plist_t));
9b816c
    |      |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9b816c
    |      |              |
9b816c
    |      |              (5) allocated here
9b816c
    |   84 |
9b816c
    |   85 |     if (!(*plist))
9b816c
    |      |        ~
9b816c
    |      |        |
9b816c
    |      |        (6) assuming ‘*plist_74(D)’ is non-NULL
9b816c
    |      |        (7) following ‘false’ branch...
9b816c
    |......
9b816c
    |   93 |     tmp = *plist;
9b816c
    |      |     ~~~
9b816c
    |      |     |
9b816c
    |      |     (8) ...to here
9b816c
    |......
9b816c
    |   99 |     if (!all_lists)
9b816c
    |      |        ~
9b816c
    |      |        |
9b816c
    |      |        (9) ‘_8’ leaks here; was allocated at (5)
9b816c
    |
9b816c
9b816c
Signed-off-by: Adrian Reber <areber@redhat.com>
9b816c
---
9b816c
 src/libnet_port_list.c | 1 +
9b816c
 1 file changed, 1 insertion(+)
9b816c
9b816c
diff --git a/src/libnet_port_list.c b/src/libnet_port_list.c
9b816c
index 942a856..a99867c 100644
9b816c
--- a/src/libnet_port_list.c
9b816c
+++ b/src/libnet_port_list.c
9b816c
@@ -101,6 +101,7 @@ libnet_plist_chain_new(libnet_t *l, libnet_plist_t **plist, char *token_list)
9b816c
         all_lists = all_lists_tmp;
9b816c
         snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
9b816c
                     "libnet_build_plist_chain: realloc %s", strerror(errno));
9b816c
+        free(tmp);
9b816c
         *plist = NULL;
9b816c
         return(-1);
9b816c
     }
9b816c
9b816c
From 60d71f03f26d349b4bf069983f625128ddcfdba8 Mon Sep 17 00:00:00 2001
9b816c
From: Adrian Reber <areber@redhat.com>
9b816c
Date: Wed, 14 Apr 2021 09:41:27 +0200
9b816c
Subject: [PATCH 2/3] =?UTF-8?q?libnet=5Fpblock.c:=20fix=20warning=20"unuse?=
9b816c
 =?UTF-8?q?d=20variable=20=E2=80=98c=E2=80=99"?=
9b816c
MIME-Version: 1.0
9b816c
Content-Type: text/plain; charset=UTF-8
9b816c
Content-Transfer-Encoding: 8bit
9b816c
9b816c
Signed-off-by: Adrian Reber <areber@redhat.com>
9b816c
---
9b816c
 src/libnet_pblock.c | 1 -
9b816c
 1 file changed, 1 deletion(-)
9b816c
9b816c
diff --git a/src/libnet_pblock.c b/src/libnet_pblock.c
9b816c
index fa46d35..e3eb184 100644
9b816c
--- a/src/libnet_pblock.c
9b816c
+++ b/src/libnet_pblock.c
9b816c
@@ -489,7 +489,6 @@ libnet_pblock_coalesce(libnet_t *l, uint8_t **packet, uint32_t *size)
9b816c
                 {
9b816c
                     if (q->flags & LIBNET_PBLOCK_DO_CHECKSUM)
9b816c
                     {
9b816c
-                        uint32_t c;
9b816c
                         uint8_t* end = *packet + l->aligner + l->total_size;
9b816c
                         uint8_t* beg = *packet + n;
9b816c
                         int ip_offset = calculate_ip_offset(l, q);
9b816c
9b816c
From 5085aebbe93b81eb93bfec5e33c04286f779ceda Mon Sep 17 00:00:00 2001
9b816c
From: Adrian Reber <areber@redhat.com>
9b816c
Date: Wed, 14 Apr 2021 10:13:23 +0200
9b816c
Subject: [PATCH 3/3] libnet_cq.c: fix 'dereference of possibly-NULL'
9b816c
MIME-Version: 1.0
9b816c
Content-Type: text/plain; charset=UTF-8
9b816c
Content-Transfer-Encoding: 8bit
9b816c
9b816c
libnet_cq.c:139:18: warning: dereference of possibly-NULL ‘new_18’ [CWE-690] [-Wanalyzer-possible-null-dereference]
9b816c
  139 |     new->context = l;
9b816c
      |     ~~~~~~~~~~~~~^~~
9b816c
  ‘libnet_cq_add.part.0’: events 1-6
9b816c
    |
9b816c
    |   71 | libnet_cq_add(libnet_t *l, char *label)
9b816c
    |      | ^~~~~~~~~~~~~
9b816c
    |      | |
9b816c
    |      | (1) entry to ‘libnet_cq_add.part.0’
9b816c
    |......
9b816c
    |   89 |     if (label == NULL)
9b816c
    |      |        ~
9b816c
    |      |        |
9b816c
    |      |        (2) following ‘false’ branch (when ‘label_1(D)’ is non-NULL)...
9b816c
    |......
9b816c
    |   97 |     if (l_cq == NULL)
9b816c
    |      |     ~~ ~
9b816c
    |      |     |  |
9b816c
    |      |     |  (4) following ‘false’ branch...
9b816c
    |      |     (3) ...to here
9b816c
    |......
9b816c
    |  124 |     if (libnet_cq_dup_check(l, label))
9b816c
    |      |     ~~  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9b816c
    |      |     |   |
9b816c
    |      |     |   (6) calling ‘libnet_cq_dup_check’ from ‘libnet_cq_add.part.0’
9b816c
    |      |     (5) ...to here
9b816c
    |
9b816c
    +--> ‘libnet_cq_dup_check’: events 7-13
9b816c
           |
9b816c
           |  269 | libnet_cq_dup_check(libnet_t *l, char *label)
9b816c
           |      | ^~~~~~~~~~~~~~~~~~~
9b816c
           |      | |
9b816c
           |      | (7) entry to ‘libnet_cq_dup_check’
9b816c
           |......
9b816c
           |  273 |     for (p = l_cq; p; p = p->next)
9b816c
           |      |                    ~  ~~~~~~~~~~~
9b816c
           |      |                    |    |
9b816c
           |      |                    |    (13) ...to here
9b816c
           |      |                    (8) following ‘true’ branch (when ‘p_6’ is non-NULL)...
9b816c
           |  274 |     {
9b816c
           |  275 |         if (p->context == l)
9b816c
           |      |         ~~ ~
9b816c
           |      |         |  |
9b816c
           |      |         |  (10) following ‘false’ branch...
9b816c
           |      |         (9) ...to here
9b816c
           |......
9b816c
           |  281 |         if (strncmp(p->context->label, label, LIBNET_LABEL_SIZE) == 0)
9b816c
           |      |         ~~ ~
9b816c
           |      |         |  |
9b816c
           |      |         |  (12) following ‘false’ branch...
9b816c
           |      |         (11) ...to here
9b816c
           |
9b816c
    <------+
9b816c
    |
9b816c
  ‘libnet_cq_add.part.0’: events 14-20
9b816c
    |
9b816c
    |  124 |     if (libnet_cq_dup_check(l, label))
9b816c
    |      |        ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9b816c
    |      |        ||
9b816c
    |      |        |(14) returning to ‘libnet_cq_add.part.0’ from ‘libnet_cq_dup_check’
9b816c
    |      |        (15) following ‘false’ branch...
9b816c
    |......
9b816c
    |  130 |     new = (libnet_cq_t *)malloc(sizeof (libnet_cq_t));
9b816c
    |      |     ~~~                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9b816c
    |      |     |                    |
9b816c
    |      |     |                    (17) this call could return NULL
9b816c
    |      |     (16) ...to here
9b816c
    |  131 |     if (l_cq == NULL)
9b816c
    |      |        ~
9b816c
    |      |        |
9b816c
    |      |        (18) following ‘false’ branch...
9b816c
    |......
9b816c
    |  139 |     new->context = l;
9b816c
    |      |     ~~~~~~~~~~~~~~~~
9b816c
    |      |     |            |
9b816c
    |      |     |            (20) ‘new_18’ could be NULL: unchecked value from (17)
9b816c
    |      |     (19) ...to here
9b816c
    |
9b816c
9b816c
Signed-off-by: Adrian Reber <areber@redhat.com>
9b816c
---
9b816c
 src/libnet_cq.c | 2 +-
9b816c
 1 file changed, 1 insertion(+), 1 deletion(-)
9b816c
9b816c
diff --git a/src/libnet_cq.c b/src/libnet_cq.c
9b816c
index 2234cbc..b3c5677 100644
9b816c
--- a/src/libnet_cq.c
9b816c
+++ b/src/libnet_cq.c
9b816c
@@ -128,7 +128,7 @@ libnet_cq_add(libnet_t *l, char *label)
9b816c
     }
9b816c
 
9b816c
     new = (libnet_cq_t *)malloc(sizeof (libnet_cq_t));
9b816c
-    if (l_cq == NULL)
9b816c
+    if (new == NULL)
9b816c
     {
9b816c
         snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
9b816c
                 "%s(): can't malloc new context queue: %s",