From 847a6d2306650614c7e9d910a521a0d8a29b07b9 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 29 Dec 2020 11:25:35 -0500 Subject: [PATCH] Fix #544, add pointer check Add parameter check to OS_SocketSendTo and adjust coverage test to validate. --- src/os/shared/src/osapi-sockets.c | 1 + .../shared/src/coveragetest-sockets.c | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/os/shared/src/osapi-sockets.c b/src/os/shared/src/osapi-sockets.c index 1aad07df0..1972a65cc 100644 --- a/src/os/shared/src/osapi-sockets.c +++ b/src/os/shared/src/osapi-sockets.c @@ -437,6 +437,7 @@ int32 OS_SocketSendTo(osal_id_t sock_id, const void *buffer, size_t buflen, cons /* Check Parameters */ OS_CHECK_POINTER(buffer); OS_CHECK_SIZE(buflen); + OS_CHECK_POINTER(RemoteAddr); return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, sock_id, &token); if (return_code == OS_SUCCESS) diff --git a/src/unit-test-coverage/shared/src/coveragetest-sockets.c b/src/unit-test-coverage/shared/src/coveragetest-sockets.c index 938032578..3e807bbe9 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-sockets.c +++ b/src/unit-test-coverage/shared/src/coveragetest-sockets.c @@ -335,9 +335,17 @@ void Test_OS_SocketSendTo(void) UtAssert_True(actual == expected, "OS_SocketSendTo() (%ld) == OS_SUCCESS", (long)actual); expected = OS_INVALID_POINTER; - actual = OS_SocketSendTo(UT_OBJID_1, NULL, OSAL_SIZE_C(0), NULL); + actual = OS_SocketSendTo(UT_OBJID_1, NULL, sizeof(Buf), &Addr); UtAssert_True(actual == expected, "OS_SocketSendTo(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + expected = OS_INVALID_POINTER; + actual = OS_SocketSendTo(UT_OBJID_1, &Buf, sizeof(Buf), NULL); + UtAssert_True(actual == expected, "OS_SocketSendTo(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_ERR_INVALID_SIZE; + actual = OS_SocketSendTo(UT_OBJID_1, &Buf, OSAL_SIZE_C(0), &Addr); + UtAssert_True(actual == expected, "OS_SocketSendTo(0) (%ld) == OS_ERR_INVALID_SIZE", (long)actual); + /* * Should fail if not a datagram socket */