casaroli commented on code in PR #21434:
URL: https://github.com/apache/nuttx/pull/21434#discussion_r4467346911


##########
net/usrsock/usrsock_sendmsg.c:
##########
@@ -160,12 +161,15 @@ static int do_sendto_request(FAR struct usrsock_conn_s 
*conn,
 
   for (i = 0; i < msg->msg_iovlen; i++)
     {
-      req.buflen += msg->msg_iov[i].iov_len;
-    }
+      /* The sum of the iov_len values must fit in an ssize_t */
 
-  if (req.buflen > UINT32_MAX)
-    {
-      req.buflen = UINT32_MAX;
+      if (msg->msg_iov[i].iov_len > SSIZE_MAX - req.buflen)

Review Comment:
   On 64-bit `SSIZE_MAX` is far above the range of `req.buflen` (uint32_t), so 
two iovecs of 0x80000000 pass this test and `req.buflen` wraps to 0. The wrap 
this PR fixes stays on 64-bit arches; UINT32_MAX is the lower bound there, 
SSIZE_MAX is the lower bound on 32-bit.
   
   Fix: test `iov_len > MIN(SSIZE_MAX, UINT32_MAX) - req.buflen`, one bound 
that holds on both.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to