mirror of
https://github.com/pellepl/spiffs.git
synced 2026-09-20 07:57:37 +00:00
fix: reject oversized metadata paths
SPIFFS_update_meta bypassed the object-name limit enforced by every other path-based API. It returned NOT_FOUND after a lookup instead of NAME_TOO_LONG for the first invalid length. Constraint: Object names allow at most SPIFFS_OBJ_NAME_LEN - 1 bytes Rejected: Bound strcmp calls | legal callers already limit names; strncmp could prefix-match corrupted entries Confidence: high Scope-risk: narrow Directive: Keep path-length validation before SPIFFS_LOCK Tested: WSL GCC default 91/91 and metadata 92/92; ASan focused name_too_long and update_meta Not-tested: Physical flash hardware
This commit is contained in:
@@ -975,6 +975,9 @@ s32_t SPIFFS_update_meta(spiffs *fs, const char *name, const void *meta) {
|
||||
#else
|
||||
SPIFFS_API_CHECK_CFG(fs);
|
||||
SPIFFS_API_CHECK_MOUNT(fs);
|
||||
if (strlen(name) > SPIFFS_OBJ_NAME_LEN - 1) {
|
||||
SPIFFS_API_CHECK_RES(fs, SPIFFS_ERR_NAME_TOO_LONG);
|
||||
}
|
||||
SPIFFS_LOCK(fs);
|
||||
|
||||
spiffs_page_ix pix, pix_dummy;
|
||||
|
||||
@@ -720,6 +720,12 @@ TEST(name_too_long) {
|
||||
TEST_CHECK_LT(SPIFFS_rename(FS, "a", name), SPIFFS_OK);
|
||||
TEST_CHECK_EQ(SPIFFS_errno(FS), SPIFFS_ERR_NAME_TOO_LONG);
|
||||
|
||||
#if SPIFFS_OBJ_META_LEN
|
||||
u8_t meta[SPIFFS_OBJ_META_LEN] = {0};
|
||||
TEST_CHECK_LT(SPIFFS_update_meta(FS, name, meta), SPIFFS_OK);
|
||||
TEST_CHECK_EQ(SPIFFS_errno(FS), SPIFFS_ERR_NAME_TOO_LONG);
|
||||
#endif
|
||||
|
||||
return TEST_RES_OK;
|
||||
} TEST_END
|
||||
|
||||
|
||||
Reference in New Issue
Block a user