Skip to content

Commit

Permalink
Fix #544, add pointer check
Browse files Browse the repository at this point in the history
Add parameter check to OS_SocketSendTo and adjust coverage test
to validate.
  • Loading branch information
jphickey committed Dec 29, 2020
1 parent d698a4d commit 847a6d2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/os/shared/src/osapi-sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion src/unit-test-coverage/shared/src/coveragetest-sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 847a6d2

Please sign in to comment.