[linux-nfc] [neard][PATCH v2 60/73] unit: do not pass NULL to memcpy()

Krzysztof Kozlowski <[email protected]> Mon, 19 Jul 2021 13:08:06 +0200
Newsgroups org.01.lists.linux-nfc,dev.linux.lists.oe-linux-nfc
Message-ID <[email protected]>
memcpy() should not receive NULL as source pointer and such is passed
from test_snep_read_get_req_frags_client_resp() and
test_snep_read_verify_resp().  ASAN reports:

    unit/test-snep-read.c:325:2: runtime error: null pointer passed as argument 2, which is declared to never be null
    unit/test-snep-read.c:266:2: runtime error: null pointer passed as argument 2, which is declared to never be null

Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
 unit/test-snep-read.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/unit/test-snep-read.c b/unit/test-snep-read.c
index 128937ed910f..ea41ae03a8b2 100644
--- a/unit/test-snep-read.c
+++ b/unit/test-snep-read.c
@@ -261,7 +261,8 @@ static struct p2p_snep_req_frame *test_snep_build_req_frame(
 	req->version = ver;
 	req->request = req_type;
 	req->length = GUINT_TO_BE(info_len);
-	memcpy(req->ndef, data, payload_len);
+	if (data)
+		memcpy(req->ndef, data, payload_len);
 
 	return req;
 }
@@ -320,7 +321,8 @@ static struct p2p_snep_resp_frame *test_snep_build_resp_frame(
 	resp->version = ver;
 	resp->response = resp_type;
 	resp->length = GUINT_TO_BE(info_len);
-	memcpy(resp->info, data, info_len);
+	if (data)
+		memcpy(resp->info, data, info_len);
 
 	return resp;
 }
-- 
2.27.0
_______________________________________________
Linux-nfc mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s