api.h, api_lib.c, sockets.c: netbuf_ref doesn't check its internal pbuf_alloc call result and can cause a crash. lwip_send now check netbuf_ref result.

This commit is contained in:
fbernon 2007-03-28 17:26:06 +00:00
parent d956a39fec
commit 913a99dd35
4 changed files with 24 additions and 23 deletions

View File

@ -29,7 +29,7 @@ HISTORY
string, point on one of your's ethernetif field, or alloc a string you will free yourself).
It will be used by DHCP to register a client hostname, but can also be use when you call
snmp_set_sysname.
2007-03-28 Frédéric Bernon
* netif.h, netif.c: A new NETIF_FLAG_ETHARP flag is defined in netif.h, to allow to
initialize a network interface's flag with. It tell this interface is an ethernet
@ -98,6 +98,10 @@ HISTORY
++ Bug fixes:
2007-03-28 Frédéric Bernon
* api.h, api_lib.c, sockets.c: netbuf_ref doesn't check its internal pbuf_alloc call
result and can cause a crash. lwip_send now check netbuf_ref result.
2007-03-28 Simon Goldschmidt
* sockets.c Remove "#include <errno.h>" from sockets.c to avoid multiple
definition of macros (in errno.h and lwip/arch.h) if LWIP_PROVIDE_ERRNO is

View File

@ -91,16 +91,21 @@ netbuf_free(struct netbuf *buf)
buf->p = buf->ptr = NULL;
}
void
err_t
netbuf_ref(struct netbuf *buf, const void *dataptr, u16_t size)
{
if (buf->p != NULL) {
pbuf_free(buf->p);
}
buf->p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF);
if (buf->p == NULL) {
buf->ptr = NULL;
return ERR_MEM;
}
buf->p->payload = (void*)dataptr;
buf->p->len = buf->p->tot_len = size;
buf->ptr = buf->p;
return ERR_OK;
}
void
@ -275,7 +280,7 @@ netconn_delete(struct netconn *conn)
msg.type = API_MSG_DELCONN;
msg.msg.conn = conn;
api_msg_post(&msg);
api_msg_post(&msg);
/* Drain the recvmbox. */
if (conn->recvmbox != SYS_MBOX_NULL) {
@ -320,8 +325,7 @@ netconn_type(struct netconn *conn)
}
err_t
netconn_peer(struct netconn *conn, struct ip_addr *addr,
u16_t *port)
netconn_peer(struct netconn *conn, struct ip_addr *addr, u16_t *port)
{
switch (conn->type) {
case NETCONN_RAW:
@ -347,8 +351,7 @@ netconn_peer(struct netconn *conn, struct ip_addr *addr,
}
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)
{
switch (conn->type) {
case NETCONN_RAW:
@ -370,8 +373,7 @@ netconn_addr(struct netconn *conn, struct ip_addr **addr,
}
err_t
netconn_bind(struct netconn *conn, struct ip_addr *addr,
u16_t port)
netconn_bind(struct netconn *conn, struct ip_addr *addr, u16_t port)
{
struct api_msg msg;
@ -396,8 +398,7 @@ netconn_bind(struct netconn *conn, struct ip_addr *addr,
err_t
netconn_connect(struct netconn *conn, struct ip_addr *addr,
u16_t port)
netconn_connect(struct netconn *conn, struct ip_addr *addr, u16_t port)
{
struct api_msg msg;
@ -445,8 +446,7 @@ netconn_listen(struct netconn *conn)
}
if (conn->acceptmbox == SYS_MBOX_NULL) {
conn->acceptmbox = sys_mbox_new();
if (conn->acceptmbox == SYS_MBOX_NULL) {
if ((conn->acceptmbox = sys_mbox_new()) == SYS_MBOX_NULL) {
return ERR_MEM;
}
}
@ -657,8 +657,7 @@ netconn_close(struct netconn *conn)
msg.type = API_MSG_CLOSE;
msg.msg.conn = conn;
api_msg_post(&msg);
if (conn->err == ERR_MEM &&
conn->sem != SYS_SEM_NULL) {
if (conn->err == ERR_MEM && conn->sem != SYS_SEM_NULL) {
sys_sem_wait(conn->sem);
goto again;
}

View File

@ -484,12 +484,11 @@ lwip_send(int s, const void *data, int size, unsigned int flags)
return -1;
}
/* make the buffer point to the data that should
be sent */
netbuf_ref(buf, data, size);
/* send the data */
err = netconn_send(sock->conn, buf);
/* make the buffer point to the data that should be sent */
if ((err = netbuf_ref(buf, data, size))==ERR_OK) {
/* send the data */
err = netconn_send(sock->conn, buf);
}
/* deallocated the buffer */
netbuf_delete(buf);

View File

@ -82,7 +82,6 @@ struct netbuf {
struct pbuf *p, *ptr;
struct ip_addr *fromaddr;
u16_t fromport;
err_t err;
};
struct netconn {
@ -111,7 +110,7 @@ struct netbuf * netbuf_new (void);
void netbuf_delete (struct netbuf *buf);
void * netbuf_alloc (struct netbuf *buf, u16_t size);
void netbuf_free (struct netbuf *buf);
void netbuf_ref (struct netbuf *buf,
err_t netbuf_ref (struct netbuf *buf,
const void *dataptr, u16_t size);
void netbuf_chain (struct netbuf *head,
struct netbuf *tail);