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