From 37931117dd756432de7ee31b5c7956a3816f4637 Mon Sep 17 00:00:00 2001 From: Adrian Bonislawski Date: Thu, 19 Dec 2024 10:59:48 +0100 Subject: [PATCH 1/2] rimage: ensure null termination Ensure null termination in man_module_create_reloc Signed-off-by: Adrian Bonislawski --- tools/rimage/src/manifest.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/rimage/src/manifest.c b/tools/rimage/src/manifest.c index 88d37df73c67..007a59e8fcd2 100644 --- a/tools/rimage/src/manifest.c +++ b/tools/rimage/src/manifest.c @@ -512,6 +512,8 @@ static int man_module_create_reloc(struct image *image, struct manifest_module * unsigned int j; strncpy(name, (char *)sof_mod->module.name, SOF_MAN_MOD_NAME_LEN); + /* Ensure null termination */ + name[SOF_MAN_MOD_NAME_LEN] = '\0'; for (j = 0; j < image->adsp->modules->mod_man_count; j++) { if (!strncmp(name, (char *)image->adsp->modules->mod_man[j].name, From 7c682e5d3ad45ae2ac7b018892c044158b951e8c Mon Sep 17 00:00:00 2001 From: Adrian Bonislawski Date: Thu, 19 Dec 2024 11:12:28 +0100 Subject: [PATCH 2/2] rimage: fix resource leak in err handling Fix resource leak in man_module_create_reloc Signed-off-by: Adrian Bonislawski --- tools/rimage/src/manifest.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/rimage/src/manifest.c b/tools/rimage/src/manifest.c index 007a59e8fcd2..b641c177d124 100644 --- a/tools/rimage/src/manifest.c +++ b/tools/rimage/src/manifest.c @@ -502,6 +502,7 @@ static int man_module_create_reloc(struct image *image, struct manifest_module * if (!n_mod || n_mod * sizeof(*sof_mod) != section.header.data.size) { fprintf(stderr, "error: Invalid module manifests in '.module' section.\n"); + elf_section_free(§ion); return -ENOEXEC; } @@ -532,6 +533,7 @@ static int man_module_create_reloc(struct image *image, struct manifest_module * if (j == image->adsp->modules->mod_man_count) { fprintf(stderr, "error: cannot find %s in manifest.\n", name); + elf_section_free(§ion); return -ENOEXEC; } }