Networking: Fix some errors found by Coverity

This commit is contained in:
Gregory Nutt 2017-09-13 13:04:26 -06:00
parent 80412df0b1
commit cca15891c9
4 changed files with 18 additions and 5 deletions

View File

@ -615,9 +615,10 @@ int inet_listen(FAR struct socket *psock, int backlog)
* an address with the sa_family member of sockaddr set to AF_UNSPEC.
*
* Parameters:
* psock Pointer to a socket structure initialized by psock_socket()
* addr Server address (form depends on type of socket)
* addrlen Length of actual 'addr'
* psock - Pointer to a socket structure initialized by psock_socket()
* addr - Server address (form depends on type of socket). The upper
* socket layer has verified that this address is non-NULL.
* addrlen - Length of actual 'addr'
*
* Returned Value:
* 0 on success; a negated errno value on failue. See connect() for the
@ -685,7 +686,7 @@ static int inet_connect(FAR struct socket *psock,
case SOCK_DGRAM:
{
int ret = udp_connect(psock->s_conn, addr);
if (ret < 0 || addr == NULL)
if (ret < 0)
{
psock->s_flags &= ~_SF_CONNECTED;
}

View File

@ -98,6 +98,7 @@ int ipv4_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr,
return -ENOSYS;
}
#if defined(NET_TCP_HAVE_STACK) || defined(NET_UDP_HAVE_STACK)
/* Set the port number */
switch (psock->s_type)
@ -170,6 +171,9 @@ int ipv4_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr,
/* Return success */
return OK;
#else
return -EOPNOTSUPP;
#endif
}
#endif /* CONFIG_NET_IPv4 */

View File

@ -145,6 +145,14 @@ int psock_connect(FAR struct socket *psock, FAR const struct sockaddr *addr,
goto errout;
}
/* Make sure that an address was provided */
if (addr == NULL)
{
errcode = EFAULT;
goto errout;
}
/* Let the address family's connect() method handle the operation */
DEBUGASSERT(psock->s_sockif != NULL && psock->s_sockif->si_connect != NULL);

View File

@ -890,7 +890,7 @@ FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct net_driver_s *dev,
/* Get the appropriate IP domain */
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv4)
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
bool ipv6 = IFF_IS_IPv6(dev->d_flags);
domain = ipv6 ? PF_INET6 : PF_INET;
#elif defined(CONFIG_NET_IPv4)