jingfei195887 opened a new pull request, #22447:
URL: https://github.com/apache/nuttx/pull/22447
## Summary
Make `procfs_snprintf` return zero when called with a zero-sized destination
buffer. This avoids unsigned underflow in the `size - 1` limit expression.
## Impact
- The helper still returns the number of bytes copied, capped at `size - 1`
when the destination has space.
- Zero-sized calls now return zero without writing to the destination.
- The change is limited to `fs/procfs/fs_procfsutil.c`; no public interface,
Kconfig option, build input, or application migration changes.
- The measured sim image grows by 16 text bytes. No runtime speed
or memory reduction claim is made.
## Testing
I confirm that changes are verified on the local setup and work as intended.
Host: Linux x86_64, GCC 13.1.0; serial builds with two CPUs.
Base `a8bb89bf6803f9d67e60696dfaf72c4036c0c789`; head
`bb396fdb27ee28fc46a6900105dcbb0816870a16`.
- The dedicated `procfssnprintfcheck` application covers zero-sized,
complete, truncated, and one-byte buffers. The unchanged baseline reports
one failure in four checks; the branch reports zero failures in four
checks.
- The same run reads `/proc/meminfo` successfully on both baseline and
branch.
The test application is a local build input and is not included in this PR.
- Matching protected `qemu-armv7r:pnsh` and kernel `qemu-armv8a:knsh` builds
pass before and after the change.
- Make/CMake, OSTest, full-file/commit checkpatch, and the current HEAD gate
pass. The HEAD gate reports zero commits behind `upstream/master` and zero
warnings in changed files.
| Build | Before [text/data/bss] | After [text/data/bss] | Delta
[text/data/bss] |
|---|---:|---:|---:|
| sim | [551685, 2800, 12928] | [551701, 2800, 12928] | [16, 0, 0] |
| protected | [156560, 928, 14536] | [156568, 928, 14528] | [8, 0, -8] |
| kernel | [218480, 19200, 60472] | [218480, 19200, 60472] | [0, 0, 0] |
The functional logs are included below for reproducibility.
<details>
<summary>Baseline functional run</summary>
```text
rev a8bb89bf680 Documentation: Say when an ACK resets the TCP retransmission
count. build rc=0
run rc=0
log=/home/mi/test/nuttx_apache/fs-upstream/pr-procfs-memcpy-inline/baseline/run.log
nsh> procfssnprintfcheck
FAIL zero-sized buffer returns zero
PROCFS_SNPRINTF RESULT checks=4 failures=1
nsh> echo PROCFS_SNPRINTF_DONE
PROCFS_SNPRINTF_DONE
nsh> cat /proc/meminfo
total used free maxused maxfree nused nfree name
67108856 1859384 65249472 1927792 65189872 107 3 Umem
nsh> echo PROCFS_MEMINFO_DONE
PROCFS_MEMINFO_DONE
nsh> poweroff
```
</details>
<details>
<summary>Branch functional run</summary>
```text
rev bb396fdb27e fs/procfs: handle zero-sized procfs_snprintf buffers build
rc=0
run rc=0
log=/home/mi/test/nuttx_apache/fs-upstream/pr-procfs-memcpy-inline/branch/run.log
nsh> procfssnprintfcheck
PROCFS_SNPRINTF RESULT checks=4 failures=0
nsh> echo PROCFS_SNPRINTF_DONE
PROCFS_SNPRINTF_DONE
nsh> cat /proc/meminfo
total used free maxused maxfree nused nfree name
67108856 1859384 65249472 1927792 65189872 107 3 Umem
nsh> echo PROCFS_MEMINFO_DONE
PROCFS_MEMINFO_DONE
nsh> poweroff
```
</details>
<details>
<summary>Final gate</summary>
```text
target : nuttx
branch : fs/procfs-snprintf-size
head : bb396fdb27ee28fc46a6900105dcbb0816870a16
subject : fs/procfs: handle zero-sized procfs_snprintf buffers
commits : 1
base : a8bb89bf68 (merge-base with upstream/master)
behind : 0 commits of upstream/master
nuttx : bb396fdb27
apps : a1b03f8926
options : CONFIG_DEBUG_ASSERTIONS CONFIG_DEBUG_FULLOPT CONFIG_COVERAGE_NONE
host : Linux x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0
checkpatch: rc=0
signer : jingfei <[email protected]>
commits missing your Signed-off-by: 0
make build: rc=0
warnings in changed files: 0
ostest: Exiting with status 0
cmake reconfigure: rc=0
cmake build: rc=0
worktree tracked changes after: 0
RESULT: PASS
```
</details>
## PR verification Self-Check
- [x] This PR introduces only one functional change.
- [x] I have updated all required description fields above.
- [x] My PR follows the contributing guidelines for scope, coding style and
testing.
- [ ] My PR is still work in progress (not ready for review).
- [x] My PR is ready for review and can be safely merged into the 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]