This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 9ceec6e9df2 fs/procfs: Ignore a failed vsnprintf in procfs_sprintf.
9ceec6e9df2 is described below
commit 9ceec6e9df243f79ca2f4ede5a9ee9acc009dbd6
Author: Shikha Bhadoria <[email protected]>
AuthorDate: Mon Nov 30 04:39:09 2026 +0000
fs/procfs: Ignore a failed vsnprintf in procfs_sprintf.
A negative vsnprintf() result was stored in size_t and became SIZE_MAX,
so MIN(..., LINEBUF_SIZE - 1) copied 127 bytes of uninitialized stack
into the procfs buffer. Return without copying when n < 0.
Assisted-by: Cursor:Grok-4.6
Signed-off-by: Shikha Bhadoria <[email protected]>
---
fs/procfs/fs_procfsutil.c | 13 +++++++++++--
include/nuttx/fs/procfs.h | 1 +
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/fs/procfs/fs_procfsutil.c b/fs/procfs/fs_procfsutil.c
index 28f04286f6a..a33b8f19276 100644
--- a/fs/procfs/fs_procfsutil.c
+++ b/fs/procfs/fs_procfsutil.c
@@ -176,6 +176,7 @@ int procfs_snprintf(FAR char *buf, size_t size,
* Description:
* This function used to continuous format string and copy it to buffer.
* Every single string length must be smaller then LINEBUF_SIZE.
+ * If vsnprintf() fails, this function copies nothing.
*
* Input Parameters:
* buf - The address of the user's receive buffer.
@@ -195,12 +196,20 @@ void procfs_sprintf(FAR char *buf, size_t size, FAR off_t
*offset,
size_t linesize;
size_t copysize;
va_list ap;
+ int n;
va_start(ap, format);
- linesize = vsnprintf(linebuf, LINEBUF_SIZE, format, ap);
+ n = vsnprintf(linebuf, LINEBUF_SIZE, format, ap);
va_end(ap);
- linesize = MIN(linesize, LINEBUF_SIZE - 1);
+ /* A negative result is an error. Do not promote it to size_t. */
+
+ if (n < 0)
+ {
+ return;
+ }
+
+ linesize = MIN((size_t)n, LINEBUF_SIZE - 1);
if (*offset > 0)
{
diff --git a/include/nuttx/fs/procfs.h b/include/nuttx/fs/procfs.h
index 6a61f76d2bf..bc7fa849237 100644
--- a/include/nuttx/fs/procfs.h
+++ b/include/nuttx/fs/procfs.h
@@ -234,6 +234,7 @@ int procfs_snprintf(FAR char *buf, size_t size,
* Description:
* This function used to continuous format string and copy it to buffer.
* Every single string length must be smaller then LINEBUF_SIZE.
+ * If vsnprintf() fails, this function copies nothing.
*
* Input Parameters:
* buf - The address of the user's receive buffer.