Swatantra-66 commented on code in PR #21434:
URL: https://github.com/apache/nuttx/pull/21434#discussion_r4467018906


##########
net/usrsock/usrsock_sendmsg.c:
##########
@@ -160,12 +161,16 @@ 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 and uint32_t */
 
-  if (req.buflen > UINT32_MAX)
-    {
-      req.buflen = UINT32_MAX;
+      if (msg->msg_iov[i].iov_len > SSIZE_MAX - req.buflen ||
+          msg->msg_iov[i].iov_len > UINT32_MAX - req.buflen)

Review Comment:
   On 32-bit platforms, SSIZE_MAX (2 GB) is strictly smaller than UINT32_MAX (4 
GB), so checking UINT32_MAX was redundant. I updated it to check only SSIZE_MAX 
to match POSIX IEEE Std 1003.1 for sendmsg() and align with 
net/inet/inet_sockif.c and fs/vfs/fs_uio.c



-- 
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