* [PATCH v4] tools/bootconfig: fix resource leak in apply_xbc()
@ 2020-05-08 12:09 Yunfeng Ye
2020-05-08 13:42 ` Markus Elfring
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Yunfeng Ye @ 2020-05-08 12:09 UTC (permalink / raw)
To: mhiramat, linux-kernel, Markus.Elfring, rostedt, kernel-janitors,
dan.carpenter
Cc: Shiyuan Hu, Hewenliang
An error is found by a internel analysis tool:
"Memory leak: data" and "Resource leak: fd" in tools/bootconfig/main.c
Fix the @data and @fd allocations that are leaked in the error path of
apply_xbc().
Fixes: 85c46b78da58 ("bootconfig: Add bootconfig magic word for indicating bootconfig explicitly")
Fixes: 950313ebf79c ("tools: bootconfig: Add bootconfig command")
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
v3 -> v4:
- update the commit message
v2 -> v3:
- set 'ret' to 0 before returning on success
v1 -> v2:
- complete the error handling at other error path
- add "Fixes" tag
tools/bootconfig/main.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c
index 16b9a420e6fd..17a9837dcfaa 100644
--- a/tools/bootconfig/main.c
+++ b/tools/bootconfig/main.c
@@ -314,31 +314,35 @@ 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);
- return ret;
+ goto free_data;
}
/* Apply new one */
fd = open(path, O_RDWR | O_APPEND);
if (fd < 0) {
pr_err("Failed to open %s: %d\n", path, fd);
- return fd;
+ ret = fd;
+ goto free_data;
}
/* 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 close_fd;
}
/* Write a magic word of the bootconfig */
ret = write(fd, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN);
- if (ret < 0) {
+ if (ret < 0)
pr_err("Failed to apply a boot config magic: %d\n", ret);
- return ret;
- }
+
+ ret = 0;
+
+close_fd:
close(fd);
+free_data:
free(data);
- return 0;
+ return ret;
}
int usage(void)
--
1.8.3.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v4] tools/bootconfig: fix resource leak in apply_xbc()
2020-05-08 12:09 [PATCH v4] tools/bootconfig: fix resource leak in apply_xbc() Yunfeng Ye
@ 2020-05-08 13:42 ` Markus Elfring
2020-05-08 14:40 ` Dan Carpenter
2020-05-08 15:42 ` [PATCH v4] tools/bootconfig: Completion of error handling Markus Elfring
2 siblings, 0 replies; 5+ messages in thread
From: Markus Elfring @ 2020-05-08 13:42 UTC (permalink / raw)
To: Yunfeng Ye, Steven Rostedt, Masami Hiramatsu
Cc: linux-kernel, kernel-janitors, Shiyuan Hu, Hewenliang,
Dan Carpenter
> An error is found by a internel analysis tool:
> "Memory leak: data" and "Resource leak: fd" in tools/bootconfig/main.c
If such an information will ever be integrated into a final commit message,
I would prefer a wording variant like the following.
Two issues were pointed out by an internal source code analysis tool:
* Line …:
Memory leak: data
* Line …:
Resource leak: fd
Each of these issues has got a different importance for this function implementation.
> Fix the @data and @fd allocations that are leaked in the error path of
> apply_xbc().
How do you think about to replace the @ characters by other delimiters
for the relevant identifiers?
Regards,
Markus
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v4] tools/bootconfig: fix resource leak in apply_xbc()
2020-05-08 12:09 [PATCH v4] tools/bootconfig: fix resource leak in apply_xbc() Yunfeng Ye
2020-05-08 13:42 ` Markus Elfring
@ 2020-05-08 14:40 ` Dan Carpenter
2020-05-08 14:51 ` Dan Carpenter
2020-05-08 15:42 ` [PATCH v4] tools/bootconfig: Completion of error handling Markus Elfring
2 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2020-05-08 14:40 UTC (permalink / raw)
To: Yunfeng Ye
Cc: mhiramat, linux-kernel, Markus.Elfring, rostedt, kernel-janitors,
Shiyuan Hu, Hewenliang
Looks good thanks!
Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>
regards,
dan carpenter
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v4] tools/bootconfig: fix resource leak in apply_xbc()
2020-05-08 14:40 ` Dan Carpenter
@ 2020-05-08 14:51 ` Dan Carpenter
0 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2020-05-08 14:51 UTC (permalink / raw)
To: Yunfeng Ye
Cc: mhiramat, linux-kernel, Markus.Elfring, rostedt, kernel-janitors,
Shiyuan Hu, Hewenliang
On Fri, May 08, 2020 at 05:40:09PM +0300, Dan Carpenter wrote:
> Looks good thanks!
>
> Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>
I was also absolutely fine with the v3 patch as well.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v4] tools/bootconfig: Completion of error handling
2020-05-08 12:09 [PATCH v4] tools/bootconfig: fix resource leak in apply_xbc() Yunfeng Ye
2020-05-08 13:42 ` Markus Elfring
2020-05-08 14:40 ` Dan Carpenter
@ 2020-05-08 15:42 ` Markus Elfring
2 siblings, 0 replies; 5+ messages in thread
From: Markus Elfring @ 2020-05-08 15:42 UTC (permalink / raw)
To: Yunfeng Ye, Steven Rostedt, Masami Hiramatsu, kernel-janitors
Cc: linux-kernel, Shiyuan Hu, Hewenliang, Dan Carpenter
…
> +++ b/tools/bootconfig/main.c
> @@ -314,31 +314,35 @@ int apply_xbc(const char *path, const char *xbc_path)
…
> +close_fd:
> close(fd);
Do analysis tools point any software development concerns out
at this source code place?
https://wiki.sei.cmu.edu/confluence/display/c/ERR33-C.+Detect+and+handle+standard+library+errors#ERR33-C.Detectandhandlestandardlibraryerrors-AutomatedDetection
Regards,
Markus
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-05-08 15:42 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-08 12:09 [PATCH v4] tools/bootconfig: fix resource leak in apply_xbc() Yunfeng Ye
2020-05-08 13:42 ` Markus Elfring
2020-05-08 14:40 ` Dan Carpenter
2020-05-08 14:51 ` Dan Carpenter
2020-05-08 15:42 ` [PATCH v4] tools/bootconfig: Completion of error handling Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).