[PATCH 2/4] ipcpd: Fix false positive incompatible malloc type

  • From: Dimitri Staessens <dimitri.staessens@xxxxxxxx>
  • To: ouroboros@xxxxxxxxxxxxx
  • Date: Fri, 25 May 2018 18:10:18 +0200

A malloc was performed with a mgmt_msg type and converted to a uint8_t
buffer for serialization, which triggers a false positive warning with
the clang static analyzer.

Signed-off-by: Dimitri Staessens <dimitri.staessens@xxxxxxxx>
---
 src/ipcpd/udp/main.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/ipcpd/udp/main.c b/src/ipcpd/udp/main.c
index be7491f..26f993c 100644
--- a/src/ipcpd/udp/main.c
+++ b/src/ipcpd/udp/main.c
@@ -236,23 +236,21 @@ static int ipcp_udp_port_alloc_resp(uint32_t dst_ip_addr,
                                     uint16_t dst_udp_port,
                                     int      response)
 {
-        uint8_t *         buf;
         struct mgmt_msg * msg;
         int               ret;
 
-        buf = malloc(sizeof(*msg));
-        if (buf == NULL)
+        msg = malloc(sizeof(*msg));
+        if (msg == NULL)
                 return -1;
 
-        msg               = (struct mgmt_msg *) buf;
         msg->code         = FLOW_REPLY;
         msg->src_udp_port = src_udp_port;
         msg->dst_udp_port = dst_udp_port;
         msg->response     = response;
 
-        ret = send_shim_udp_msg(buf, sizeof(*msg), dst_ip_addr);
+        ret = send_shim_udp_msg((uint8_t *) msg, sizeof(*msg), dst_ip_addr);
 
-        free(buf);
+        free(msg);
 
         return ret;
 }
-- 
2.17.0


Other related posts:

  • » [PATCH 2/4] ipcpd: Fix false positive incompatible malloc type - Dimitri Staessens