gattrib: Fix passing NULL to memcpy
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Tue, 21 Dec 2021 20:48:31 +0000 (12:48 -0800)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:38 +0000 (19:08 +0530)
This fixes the following runtime error:

  attrib/gattrib.c:198:2: runtime error: null pointer passed as
  argument 2, which is declared to never be null

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
attrib/gattrib.c

index 2caa703..07f8096 100755 (executable)
@@ -195,7 +195,9 @@ static uint8_t *construct_full_pdu(uint8_t opcode, const void *pdu,
                return NULL;
 
        buf[0] = opcode;
-       memcpy(buf + 1, pdu, length);
+
+       if (pdu && length)
+               memcpy(buf + 1, pdu, length);
 
        return buf;
 }