Copilot commented on code in PR #21807:
URL: https://github.com/apache/nuttx/pull/21807#discussion_r4551575662


##########
libs/libc/userfs/lib_userfs.c:
##########
@@ -124,14 +124,14 @@ static inline int userfs_open_dispatch(FAR struct 
userfs_info_s *info,
       return -EINVAL;
     }
 
-  pathlen = strlen(req->relpath);
+  pathlen = strlen(req->relpath) + 1;
   if (pathlen > info->mxwrite)
     {
       return -EINVAL;
     }
 
   expected = SIZEOF_USERFS_OPEN_REQUEST_S(pathlen);
-  if (expected >= reqlen)
+  if (expected > reqlen)
     {
       return -EINVAL;
     }

Review Comment:
   Changing the validation from `expected >= reqlen` to `expected > reqlen` now 
permits `expected < reqlen` (i.e., extra trailing bytes) for requests. If the 
protocol expects an exact match, this weakens input validation and can allow 
malformed/ambiguous packets. Consider enforcing exact sizing (e.g., reject when 
`expected != reqlen`) consistently across all dispatch handlers updated in this 
PR.



##########
libs/libc/userfs/lib_userfs.c:
##########
@@ -747,24 +747,24 @@ static inline int userfs_rename_dispatch(FAR struct 
userfs_info_s *info,
       return -EINVAL;
     }
 
-  oldpathlen = strlen(req->oldrelpath);
+  oldpathlen = strlen(req->oldrelpath) + 1;
   newoffset  = req->newoffset;
 
-  if (oldpathlen >= newoffset)
+  if (oldpathlen > newoffset)
     {
       return -EINVAL;
     }
 
   newrelpath = &req->oldrelpath[newoffset];
-  newpathlen = strlen(newrelpath);
+  newpathlen = strlen(newrelpath) + 1;

Review Comment:
   The `newoffset` check is too weak for safe parsing. As written, `newoffset` 
values greater than `oldpathlen` are accepted, and `strlen(newrelpath)` may 
read outside the received request buffer if `newoffset` points past the actual 
payload. Since the client sets `req->newoffset = oldpathlen`, the server should 
require an exact match (reject when `newoffset != oldpathlen`) and validate 
`newoffset` against `reqlen` before computing `newpathlen` (e.g., use a bounded 
length scan based on remaining bytes).



##########
libs/libc/userfs/lib_userfs.c:
##########
@@ -702,14 +702,14 @@ static inline int userfs_rmdir_dispatch(FAR struct 
userfs_info_s *info,
       return -EINVAL;
     }
 
-  pathlen = strlen(req->relpath);
+  pathlen = strlen(req->relpath) + 1;
   if (pathlen > info->mxwrite)
     {
       return -EINVAL;
     }
 
   expected = SIZEOF_USERFS_MKDIR_REQUEST_S(pathlen);
-  if (expected >= reqlen)
+  if (expected > reqlen)
     {
       return -EINVAL;
     }

Review Comment:
   `userfs_rmdir_dispatch` appears to compute `expected` using 
`SIZEOF_USERFS_MKDIR_REQUEST_S(pathlen)`. This looks like the wrong 
request-size macro for an RMDIR request and can cause incorrect length 
validation. Use the corresponding RMDIR sizing macro (likely 
`SIZEOF_USERFS_RMDIR_REQUEST_S(pathlen)`) so the check matches the actual 
request layout.



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