2021-12-23 19:50:08

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH v4 4/4] gattrib: Fix passing NULL to memcpy

From: Luiz Augusto von Dentz <[email protected]>

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
---
attrib/gattrib.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/attrib/gattrib.c b/attrib/gattrib.c
index 270a37ebe..041b9d289 100644
--- a/attrib/gattrib.c
+++ b/attrib/gattrib.c
@@ -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;
}
--
2.33.1