jingfei195887 opened a new pull request, #21807:
URL: https://github.com/apache/nuttx/pull/21807
## Summary
* The userfs client copies each request path with
`strlcpy(req->relpath, relpath, priv->mxwrite)` after checking
`strlen(relpath) > priv->mxwrite`. A path of exactly `mxwrite` characters
passes the check, but `strlcpy()` keeps only `mxwrite - 1` of them, so the
server receives a different, shorter name.
* Count the trailing NUL in `pathlen` itself, so the length check, the
`memcpy()` and the request size all use the same value. On the server side
(`libs/libc/userfs`) count the NUL the same way and accept
`expected == reqlen` as the exact match it now is.
## Impact
* New or changed feature: NO.
* Impact on user: YES. A userfs path of exactly `mxwrite` characters now
fails
with `E2BIG`, like longer paths already do, instead of being truncated to a
different name. Shorter paths behave as before.
* Impact on build: NO.
* Impact on hardware: NO.
* Impact on documentation: NO.
* Impact on security: NO.
* Impact on compatibility: NO. The request bytes on the wire are unchanged
(path plus NUL, same size), and the client and server come from the same
tree.
## Testing
I confirm that changes are verified on local setup and works as intended:
* Build Host: Ubuntu 22.04 x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0
* Target: `sim:nsh` with `CONFIG_NET`, `CONFIG_NET_IPv4`, `CONFIG_NET_UDP`,
`CONFIG_NET_LOOPBACK` and `CONFIG_FS_USERFS`, master 5d79bf455d. Verified
on
sim only.
A test task runs `userfs_run()` with `mxwrite = 8` and a server whose
`open()` records the path it receives, then opens paths of 7, 8 and 9
characters.
Testing logs before change:
```
open("abcdefg") len=7: errno=2 server got "abcdefg"
open("abcdefgh") len=8: errno=2 server got "abcdefg"
open("abcdefghi") len=9: errno=7 server got ""
```
Testing logs after change:
```
open("abcdefg") len=7: errno=2 server got "abcdefg"
open("abcdefgh") len=8: errno=7 server got ""
open("abcdefghi") len=9: errno=7 server got ""
```
* `./tools/checkpatch.sh -m -g master..HEAD`: all checks pass.
* Make and CMake builds pass with no new warnings; `ostest` exits with
status 0.
## PR verification Self-Check
* [x] This PR introduces only one functional change.
* [x] I have updated all required description fields above.
* [x] My PR adheres to Contributing Guidelines and Documentation (git commit
title and message, coding standard, etc).
* [ ] My PR is still work in progress (not ready for review).
* [x] My PR is ready for review and can be safely merged into a codebase.
--
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]