xiaoxiang781216 commented on code in PR #1623:
URL: https://github.com/apache/nuttx-apps/pull/1623#discussion_r1181211199


##########
netutils/tftpc/tftpc_packets.c:
##########
@@ -122,13 +122,16 @@ int tftp_sockinit(struct sockaddr_in *server, in_addr_t 
addr)
  *
  ****************************************************************************/
 
-int tftp_mkreqpacket(uint8_t *buffer, int opcode, const char *path,
-                     bool binary)
+int tftp_mkreqpacket(uint8_t *buffer, size_t len, int opcode,
+                     const char *path, bool binary)
 {
+  int ret;
+
   buffer[0] = opcode >> 8;
   buffer[1] = opcode & 0xff;
-  return sprintf((char *)&buffer[2], "%s%c%s", path, 0,
+  ret = snprintf((char *)&buffer[2], len - 2, "%s%c%s", path, 0,
                  tftp_mode(binary)) + 3;
+  return ret < len ? ret : len;

Review Comment:
   No, since this function states that it never fail:
   ```
   /****************************************************************************
    * Name: tftp_mkreqpacket
    *
    * Description:
    *   RRQ or WRQ message format:
    *
    *     2 bytes: Opcode (network order == big-endian)
    *     N bytes: Filename
    *     1 byte:  0
    *     N bytes: mode
    *     1 byte:  0
    *
    * Return
    *  Then number of bytes in the request packet (never fails)
    *
    
****************************************************************************/
   
   int tftp_mkreqpacket(uint8_t *buffer, size_t len, int opcode,
                        const char *path, bool binary)
   ```
   all callers pass the returned value as length to send directly without any 
check.



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