Skip to content

Commit 654e690

Browse files
sudarsan-22kartben
authored andcommitted
settings: zms: fix out-of-bounds null terminator write
Previously, zms_read() could fill the buffer up to sizeof(rdname), leaving no space for the null terminator, which could cause an out-of-bounds write. This change reduces the read size to sizeof(rdname) - 1 and appends a '\0' manually, ensuring the buffer is always null-terminated safely. Fixes: CID 516244 Fixes: #90533 Signed-off-by: sudarsan N <sudarsansamy2002@gmail.com>
1 parent e93a633 commit 654e690

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

subsys/settings/src/settings_zms.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ static int settings_zms_save(struct settings_store *cs, const char *name, const
432432

433433
for (int i = 0; i <= cf->hash_collision_num; i++) {
434434
rc = zms_read(&cf->cf_zms, name_hash + i * LSB_GET(ZMS_COLLISIONS_MASK), &rdname,
435-
sizeof(rdname));
435+
sizeof(rdname) - 1);
436436
if (rc == -ENOENT) {
437437
if (first_available_hash_index < 0) {
438438
first_available_hash_index = i;
@@ -445,6 +445,8 @@ static int settings_zms_save(struct settings_store *cs, const char *name, const
445445
/* Settings entry exist, let's verify if this is the same
446446
* name
447447
*/
448+
__ASSERT_NO_MSG(rc < sizeof(rdname));
449+
448450
rdname[rc] = '\0';
449451
if ((rc == name_len) && !memcmp(name, rdname, rc)) {
450452
/* Hash exist and the names are equal, we should

0 commit comments

Comments
 (0)