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 <35417409+Old-Ding@users.noreply.github.com>
This commit is contained in:
Old-Ding 2026-07-06 06:56:12 +08:00 committed by Alin Jerpelea
parent c3494e47e3
commit 4b1a1bdca9

View file

@ -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;
}