This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch releases/13.0
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/releases/13.0 by this push:
     new 1354a57ad9c fs/partition: bound TXTABLE partition names
1354a57ad9c is described below

commit 1354a57ad9ced98ade396aa3bfb0b973626a21e2
Author: Old-Ding <[email protected]>
AuthorDate: Mon Jul 6 06:56:12 2026 +0800

    fs/partition: bound TXTABLE partition names
    
    Limit the parsed TXTABLE name field to NAME_MAX and reject entries that do 
not provide all three required fields. This avoids writing past struct 
partition_s.name when a text partition table contains an overlong name.
    
    Signed-off-by: Old-Ding <[email protected]>
---
 fs/partition/fs_txtable.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/partition/fs_txtable.c b/fs/partition/fs_txtable.c
index fdba147d505..b1eb21f2d6d 100644
--- a/fs/partition/fs_txtable.c
+++ b/fs/partition/fs_txtable.c
@@ -30,6 +30,7 @@
 #include <stdio.h>
 
 #include <nuttx/kmalloc.h>
+#include <nuttx/macro.h>
 
 #include "partition.h"
 #include "fs_heap.h"
@@ -44,6 +45,7 @@
 
 #define TXTABLE_MAGIC   "TXTABLE0"
 #define TXTABLE_LENGTH  (state->erasesize + 1)
+#define TXTABLE_NAME_FMT "%" STRINGIFY(NAME_MAX) "s"
 
 /****************************************************************************
  * Public Functions
@@ -157,12 +159,13 @@ int parse_txtable_partition(FAR struct partition_state_s 
*state,
           break;
         }
 
-      ret = sscanf(token, "%s %zx %zx",
+      ret = sscanf(token, TXTABLE_NAME_FMT " %zx %zx",
                    part[i].name,
                    &part[i].nblocks,
                    &part[i].firstblock);
-      if (ret < 0)
+      if (ret != 3)
         {
+          ret = -EFTYPE;
           goto out;
         }
 

Reply via email to