From: Yunfeng Ye <yeyunfeng@huawei.com> To: Markus Elfring <Markus.Elfring@web.de>, Steven Rostedt <rostedt@goodmis.org>, Masami Hiramatsu <mhiramat@kernel.org> Cc: <kernel-janitors@vger.kernel.org>, <linux-kernel@vger.kernel.org>, Hewenliang <hewenliang4@huawei.com>, Shiyuan Hu <hushiyuan@huawei.com> Subject: Re: [PATCH] tools/bootconfig: fix resource leak in apply_xbc() Date: Fri, 8 May 2020 14:41:31 +0800 [thread overview] Message-ID: <9359694c-57bf-729f-593f-6e25c4b115f6@huawei.com> (raw) In-Reply-To: <63755ce8-5e1b-6c54-2f74-649cc2546371@web.de> On 2020/5/8 4:30, Markus Elfring wrote: >> The @data and @fd is leak in the error path of apply_xbc(), so this >> patch fix it. > > I suggest to improve this change description. > > * Please use an imperative wording. > > * Would you like to add the tag “Fixes”? > > >> +++ b/tools/bootconfig/main.c >> @@ -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; >> } > > I propose to adjust the exception handling. > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?id=6e7f2eacf09811d092c1b41263108ac7fe0d089d#n450 > > - return ret; > + goto free_data; > > >> @@ -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; > > - 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 out; > > + goto free_data; > > >> } >> /* Write a magic word of the bootconfig */ >> ret = write(fd, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN); >> if (ret < 0) { > > - if (ret < 0) { > + if (ret < 0) > > >> pr_err("Failed to apply a boot config magic: %d\n", ret); >> - return ret; >> + goto out; > > I suggest to avoid an extra jump at such a place. > > >> } > > - } > + > > >> +out: > > +close_fd: >> close(fd); > > +free_data: >> free(data); > > > How do you think about to complete the error handling also at other > source code places? > ok, I will modify and send the patch v2, thanks. > Regards, > Markus > >
WARNING: multiple messages have this Message-ID (diff)
From: Yunfeng Ye <yeyunfeng@huawei.com> To: Markus Elfring <Markus.Elfring@web.de>, Steven Rostedt <rostedt@goodmis.org>, Masami Hiramatsu <mhiramat@kernel.org> Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, Hewenliang <hewenliang4@huawei.com>, Shiyuan Hu <hushiyuan@huawei.com> Subject: Re: [PATCH] tools/bootconfig: fix resource leak in apply_xbc() Date: Fri, 08 May 2020 06:41:31 +0000 [thread overview] Message-ID: <9359694c-57bf-729f-593f-6e25c4b115f6@huawei.com> (raw) In-Reply-To: <63755ce8-5e1b-6c54-2f74-649cc2546371@web.de> On 2020/5/8 4:30, Markus Elfring wrote: >> The @data and @fd is leak in the error path of apply_xbc(), so this >> patch fix it. > > I suggest to improve this change description. > > * Please use an imperative wording. > > * Would you like to add the tag “Fixes”? > > >> +++ b/tools/bootconfig/main.c >> @@ -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; >> } > > I propose to adjust the exception handling. > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?idn7f2eacf09811d092c1b41263108ac7fe0d089d#n450 > > - return ret; > + goto free_data; > > >> @@ -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; > > - 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 out; > > + goto free_data; > > >> } >> /* Write a magic word of the bootconfig */ >> ret = write(fd, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN); >> if (ret < 0) { > > - if (ret < 0) { > + if (ret < 0) > > >> pr_err("Failed to apply a boot config magic: %d\n", ret); >> - return ret; >> + goto out; > > I suggest to avoid an extra jump at such a place. > > >> } > > - } > + > > >> +out: > > +close_fd: >> close(fd); > > +free_data: >> free(data); > > > How do you think about to complete the error handling also at other > source code places? > ok, I will modify and send the patch v2, thanks. > Regards, > Markus > >
next prev parent reply other threads:[~2020-05-08 6:41 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-05-07 20:30 [PATCH] tools/bootconfig: fix resource leak in apply_xbc() Markus Elfring 2020-05-07 20:30 ` Markus Elfring 2020-05-08 6:41 ` Yunfeng Ye [this message] 2020-05-08 6:41 ` Yunfeng Ye -- strict thread matches above, loose matches on Subject: below -- 2020-05-07 9:23 Yunfeng Ye 2020-05-07 15:56 ` Masami Hiramatsu 2020-05-07 15:58 ` Masami Hiramatsu 2020-05-07 18:16 ` Steven Rostedt
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=9359694c-57bf-729f-593f-6e25c4b115f6@huawei.com \ --to=yeyunfeng@huawei.com \ --cc=Markus.Elfring@web.de \ --cc=hewenliang4@huawei.com \ --cc=hushiyuan@huawei.com \ --cc=kernel-janitors@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=mhiramat@kernel.org \ --cc=rostedt@goodmis.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.