mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-09-13 02:05:43 +00:00
netconn_write_vectors_partly() watch out for overflow of data to send (must fit into INT_MAX for sockets)
This commit is contained in:
parent
4dd378b126
commit
270fdfff07
@ -877,13 +877,6 @@ netconn_write_vectors_partly(struct netconn *conn, struct netvector *vectors, u1
|
|||||||
|
|
||||||
LWIP_ERROR("netconn_write: invalid conn", (conn != NULL), return ERR_ARG;);
|
LWIP_ERROR("netconn_write: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||||
LWIP_ERROR("netconn_write: invalid conn->type", (NETCONNTYPE_GROUP(conn->type)== NETCONN_TCP), return ERR_VAL;);
|
LWIP_ERROR("netconn_write: invalid conn->type", (NETCONNTYPE_GROUP(conn->type)== NETCONN_TCP), return ERR_VAL;);
|
||||||
size = 0;
|
|
||||||
for (i = 0; i < vectorcnt; i++) {
|
|
||||||
size += vectors[i].len;
|
|
||||||
}
|
|
||||||
if (size == 0) {
|
|
||||||
return ERR_OK;
|
|
||||||
}
|
|
||||||
dontblock = netconn_is_nonblocking(conn) || (apiflags & NETCONN_DONTBLOCK);
|
dontblock = netconn_is_nonblocking(conn) || (apiflags & NETCONN_DONTBLOCK);
|
||||||
#if LWIP_SO_SNDTIMEO
|
#if LWIP_SO_SNDTIMEO
|
||||||
if (conn->send_timeout != 0) {
|
if (conn->send_timeout != 0) {
|
||||||
@ -896,6 +889,22 @@ netconn_write_vectors_partly(struct netconn *conn, struct netvector *vectors, u1
|
|||||||
return ERR_VAL;
|
return ERR_VAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* sum up the total size */
|
||||||
|
size = 0;
|
||||||
|
for (i = 0; i < vectorcnt; i++) {
|
||||||
|
size += vectors[i].len;
|
||||||
|
if (size < vectors[i].len) {
|
||||||
|
/* overflow */
|
||||||
|
return ERR_VAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (size == 0) {
|
||||||
|
return ERR_OK;
|
||||||
|
} else if (size > INT_MAX) {
|
||||||
|
/* this is required by the socket layer (cannot send full size_t range) */
|
||||||
|
return ERR_VAL;
|
||||||
|
}
|
||||||
|
|
||||||
API_MSG_VAR_ALLOC(msg);
|
API_MSG_VAR_ALLOC(msg);
|
||||||
/* non-blocking write sends as much */
|
/* non-blocking write sends as much */
|
||||||
API_MSG_VAR_REF(msg).conn = conn;
|
API_MSG_VAR_REF(msg).conn = conn;
|
||||||
|
Loading…
Reference in New Issue
Block a user