tools/bootconfig: fix resource leak in apply_xbc()
PATCH 1/1 tools/bootconfig: fix resource leak in apply_xbc()
The @data and @fd is leak in the error path of apply_xbc(), so this patch fix it.
Signed-off-by Yunfeng Ye <[email protected]>
--- tools/bootconfig/main.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
tools/bootconfig/main.c +6 -3
@@ -314,6 +314,7 @@ int apply_xbc(const char *path, const char *xbc_path) ret =delete_xbc (path);if (ret <0 ) {pr_err ("Failed to delete previous boot config: %d\n" , ret); +free (data);return ret; }
@@ -321,24 +322,26 @@ int apply_xbc(const char *path, const char *xbc_path) fd =open (path,O_RDWR |O_APPEND );if (fd <0 ) {pr_err ("Failed to open %s: %d\n" , path, fd); +free (data);return fd; }/* TODO: Ensure the @path is initramfs/initrd image */ ret =write (fd, data, size +8 );if (ret <0 ) {pr_err ("Failed to apply a boot config: %d\n" , ret); -return ret; + goto out; }/* Write a magic word of the bootconfig */ ret =write (fd,BOOTCONFIG_MAGIC ,BOOTCONFIG_MAGIC_LEN );if (ret <0 ) {pr_err ("Failed to apply a boot config magic: %d\n" , ret); -return ret; + goto out; } +out:close (fd);free (data); -return 0 ; +return ret; }int usage (void )
Signature · 1 line
1.8.3.1
Quoted 2 lines · On Thu, 7 May 2020 17:23:36 +0800 Yunfeng Ye <[email protected]> wrote:
The @data and @fd is leak in the error path of
apply_xbc(), so this patch fix it.
Good catch! Thanks for fixing!
Acked-by Masami Hiramatsu <[email protected]>
Quoted 51 lines
Signed-off-by Yunfeng Ye <[email protected]>--- tools/bootconfig/main.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)tools/bootconfig/main.c +6
-3@@ -314,6 +314,7 @@ int apply_xbc(const char *path, const char *xbc_path) ret =delete_xbc (path);if (ret <0 ) {pr_err ("Failed to delete previous boot config: %d\n" , ret); +free (data);return ret; }@@ -321,24 +322,26 @@ int apply_xbc(const char *path, const char *xbc_path) fd =open (path,O_RDWR |O_APPEND );if (fd <0 ) {pr_err ("Failed to open %s: %d\n" , path, fd); +free (data);return fd; }/* TODO: Ensure the @path is initramfs/initrd image */ ret =write (fd, data, size +8 );if (ret <0 ) {pr_err ("Failed to apply a boot config: %d\n" , ret); -return ret; + goto out; }/* Write a magic word of the bootconfig */ ret =write (fd,BOOTCONFIG_MAGIC ,BOOTCONFIG_MAGIC_LEN );if (ret <0 ) {pr_err ("Failed to apply a boot config magic: %d\n" , ret); -return ret; + goto out; } +out:close (fd);free (data); -return 0 ; +return ret; }int usage (void )Signature · 1 line
1.8.3.1
Signature · 1 line
Masami Hiramatsu <[email protected]>
Masami Hiramatsu
maintainerQuoted 10 lines · On Fri, 8 May 2020 00:56:47 +0900 Masami Hiramatsu <[email protected]> wrote:
Quoted 2 lines · On Thu, 7 May 2020 17:23:36 +0800 Yunfeng Ye <[email protected]> wrote:
The @data and @fd is leak in the error path of
apply_xbc(), so this patch fix it.Good catch! Thanks for fixing!
Acked-by Masami Hiramatsu <[email protected]>
Hi Steve, can you pick this up?
Thank you,
Quoted 55 lines
Quoted 51 lines
Signed-off-by Yunfeng Ye <[email protected]>--- tools/bootconfig/main.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)tools/bootconfig/main.c +6
-3@@ -314,6 +314,7 @@ int apply_xbc(const char *path, const char *xbc_path) ret =delete_xbc (path);if (ret <0 ) {pr_err ("Failed to delete previous boot config: %d\n" , ret); +free (data);return ret; }@@ -321,24 +322,26 @@ int apply_xbc(const char *path, const char *xbc_path) fd =open (path,O_RDWR |O_APPEND );if (fd <0 ) {pr_err ("Failed to open %s: %d\n" , path, fd); +free (data);return fd; }/* TODO: Ensure the @path is initramfs/initrd image */ ret =write (fd, data, size +8 );if (ret <0 ) {pr_err ("Failed to apply a boot config: %d\n" , ret); -return ret; + goto out; }/* Write a magic word of the bootconfig */ ret =write (fd,BOOTCONFIG_MAGIC ,BOOTCONFIG_MAGIC_LEN );if (ret <0 ) {pr_err ("Failed to apply a boot config magic: %d\n" , ret); -return ret; + goto out; } +out:close (fd);free (data); -return 0 ; +return ret; }int usage (void )Signature · 1 line
1.8.3.1Signature · 1 line
Masami Hiramatsu <[email protected]>
Signature · 1 line
Masami Hiramatsu <[email protected]>
Quoted 9 lines · On Fri, 8 May 2020 00:58:05 +0900 Masami Hiramatsu <[email protected]> wrote:
Quoted 6 lines · On Fri, 8 May 2020 00:56:47 +0900 Masami Hiramatsu <[email protected]> wrote:
Quoted 2 lines · On Thu, 7 May 2020 17:23:36 +0800 Yunfeng Ye <[email protected]> wrote:
The @data and @fd is leak in the error path of
apply_xbc(), so this patch fix it.
Quoted 6 lines
Quoted 4 lines
Good catch! Thanks for fixing!
Acked-by Masami Hiramatsu <[email protected]>Hi Steve, can you pick this up?
Yeah. I can add it to my 'for-linus' queue. As it's just part of the tools directory, I can skip the full testing I run on my patches.
-- Steve