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:
parent
89a79b03cf
commit
5ee0432d6f
@ -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 */
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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 */
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user