net/socket: Fix sanity checking of socket interface

No error occurs even if NULL is set in the input argument
of socket API. So added an argument check process.
This commit is contained in:
SPRESENSE 2020-07-22 17:30:30 +09:00 committed by Abdelatif Guettouche
parent 89a79b03cf
commit 5ee0432d6f
5 changed files with 2 additions and 10 deletions

View File

@ -105,12 +105,10 @@ int psock_getpeername(FAR struct socket *psock, FAR struct sockaddr *addr,
* system (?)
*/
#ifdef CONFIG_DEBUG_FEATURES
if (addr == NULL || *addrlen <= 0)
if (addr == NULL || addrlen == NULL || *addrlen <= 0)
{
return -EINVAL;
}
#endif
/* Let the address family's send() method handle the operation */

View File

@ -103,7 +103,7 @@ int psock_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr,
/* Some sanity checking... */
if (addr == NULL || addrlen == NULL)
if (addr == NULL || addrlen == NULL || *addrlen <= 0)
{
return -EINVAL;
}

View File

@ -90,12 +90,10 @@ ssize_t psock_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
{
/* Verify that non-NULL pointers were passed */
#ifdef CONFIG_DEBUG_FEATURES
if (buf == NULL)
{
return -EINVAL;
}
#endif
if (from != NULL && fromlen != NULL && *fromlen <= 0)
{

View File

@ -91,12 +91,10 @@ ssize_t psock_send(FAR struct socket *psock, FAR const void *buf, size_t len,
/* Verify that non-NULL pointers were passed */
#ifdef CONFIG_DEBUG_FEATURES
if (buf == NULL)
{
return -EINVAL;
}
#endif
/* Verify that the sockfd corresponds to valid, allocated socket */

View File

@ -126,12 +126,10 @@ ssize_t psock_sendto(FAR struct socket *psock, FAR const void *buf,
/* Verify that non-NULL pointers were passed */
#ifdef CONFIG_DEBUG_FEATURES
if (buf == NULL)
{
return -EINVAL;
}
#endif
/* If to is NULL or tolen is zero, then this function is same as send (for
* connected socket types)