Skip to content

Commit

Permalink
Merge pull request #716 from jphickey/fix-544-sendto-pointer
Browse files Browse the repository at this point in the history
Fix #544, add pointer check
  • Loading branch information
astrogeco authored Jan 12, 2021
2 parents 2a6d368 + 847a6d2 commit 08c1cf1
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 @@ -405,6 +405,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 08c1cf1

Please sign in to comment.