sockets.c, api.h, api_lib.c: First step to fix "bug #20900 : Potential crash error problem with netconn_peer & netconn_addr". VERY IMPORTANT: this change cause an API breakage for netconn_peer, since a parameter type change. Any compiler should cause an error without any changes in yours netconn_peer calls (so, it can't be a "silent change"). It also reduce a little bit the footprint for socket layer (lwip_getpeername & lwip_getsockname use now a common lwip_getaddrname function since netconn_peer & netconn_addr have the same parameters).

This commit is contained in:
fbernon
2007-10-07 17:26:54 +00:00
parent e561c7b49d
commit 87e16a8f47
4 changed files with 59 additions and 53 deletions

View File

@@ -186,6 +186,15 @@ err_t
netconn_peer(struct netconn *conn, struct ip_addr *addr, u16_t *port)
{
LWIP_ERROR("netconn_peer: invalid conn", (conn != NULL), return ERR_ARG;);
LWIP_ERROR("netconn_peer: invalid addr", (addr != NULL), return ERR_ARG;);
LWIP_ERROR("netconn_peer: invalid port", (port != NULL), return ERR_ARG;);
/* Not a good safe-thread protection, will be improved */
if (conn->pcb.ip == NULL)
return ERR_CONN;
*addr = conn->pcb.ip->remote_ip;
switch (NETCONNTYPE_GROUP(conn->type)) {
#if LWIP_RAW
case NETCONN_RAW:
@@ -194,18 +203,13 @@ netconn_peer(struct netconn *conn, struct ip_addr *addr, u16_t *port)
#endif /* LWIP_RAW */
#if LWIP_UDP
case NETCONN_UDP:
if (conn->pcb.udp == NULL ||
((conn->pcb.udp->flags & UDP_FLAGS_CONNECTED) == 0))
return ERR_CONN;
*addr = (conn->pcb.udp->remote_ip);
if ((conn->pcb.udp->flags & UDP_FLAGS_CONNECTED) == 0)
return ERR_CONN;
*port = conn->pcb.udp->remote_port;
break;
#endif /* LWIP_UDP */
#if LWIP_TCP
case NETCONN_TCP:
if (conn->pcb.tcp == NULL)
return ERR_CONN;
*addr = (conn->pcb.tcp->remote_ip);
*port = conn->pcb.tcp->remote_port;
break;
#endif /* LWIP_TCP */
@@ -220,30 +224,35 @@ netconn_peer(struct netconn *conn, struct ip_addr *addr, u16_t *port)
* @param conn the netconn to query
* @param addr a pointer to which to save the local IP address
* @param port a pointer to which to save the local port (or protocol for RAW)
* @return ERR_OK if the information was retrieved
* @return ERR_CONN for invalid connections
* ERR_OK if the information was retrieved
*/
err_t
netconn_addr(struct netconn *conn, struct ip_addr **addr, u16_t *port)
netconn_addr(struct netconn *conn, struct ip_addr *addr, u16_t *port)
{
LWIP_ERROR("netconn_addr: invalid conn", (conn != NULL), return ERR_ARG;);
LWIP_ERROR("netconn_addr: invalid addr", (addr != NULL), return ERR_ARG;);
LWIP_ERROR("netconn_addr: invalid port", (port != NULL), return ERR_ARG;);
/* Not a good safe-thread protection, will be improved */
if (conn->pcb.ip == NULL)
return ERR_CONN;
*addr = conn->pcb.ip->local_ip;
switch (NETCONNTYPE_GROUP(conn->type)) {
#if LWIP_RAW
case NETCONN_RAW:
*addr = &(conn->pcb.raw->local_ip);
*port = conn->pcb.raw->protocol;
break;
#endif /* LWIP_RAW */
#if LWIP_UDP
case NETCONN_UDP:
*addr = &(conn->pcb.udp->local_ip);
*port = conn->pcb.udp->local_port;
break;
#endif /* LWIP_UDP */
#if LWIP_TCP
case NETCONN_TCP:
*addr = &(conn->pcb.tcp->local_ip);
*port = conn->pcb.tcp->local_port;
break;
#endif /* LWIP_TCP */