* [U-Boot] [PATCH] tools: mkimage: Call fclose in error path
@ 2016-12-20 8:58 Michal Simek
2016-12-20 11:01 ` Ladislav Michl
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Michal Simek @ 2016-12-20 8:58 UTC (permalink / raw)
To: u-boot
This patch is fixing missing fclose() calls
in error patch introduced by:
"tools: mkimage: Use fstat instead of stat to avoid malicious hacks"
(sha1: ebe0f53f48e8f9ecc823e533a85b05c13638c350)
Reported-by: Coverity (CID: 155064, 155065)
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
---
tools/zynqimage.c | 8 ++++++--
tools/zynqmpimage.c | 8 ++++++--
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/tools/zynqimage.c b/tools/zynqimage.c
index b47132b02a60..021d2d3fc91f 100644
--- a/tools/zynqimage.c
+++ b/tools/zynqimage.c
@@ -239,11 +239,15 @@ static void zynqimage_parse_initparams(struct zynq_header *zynqhdr,
}
err = fstat(fileno(fp), &path_stat);
- if (err)
+ if (err) {
+ fclose(fp);
return;
+ }
- if (!S_ISREG(path_stat.st_mode))
+ if (!S_ISREG(path_stat.st_mode)) {
+ fclose(fp);
return;
+ }
do {
r = fscanf(fp, "%x %x", ®init.address, ®init.data);
diff --git a/tools/zynqmpimage.c b/tools/zynqmpimage.c
index 60d8ed23b4a1..0c9a3daddd6a 100644
--- a/tools/zynqmpimage.c
+++ b/tools/zynqmpimage.c
@@ -251,11 +251,15 @@ static void zynqmpimage_parse_initparams(struct zynqmp_header *zynqhdr,
}
err = fstat(fileno(fp), &path_stat);
- if (err)
+ if (err) {
+ fclose(fp);
return;
+ }
- if (!S_ISREG(path_stat.st_mode))
+ if (!S_ISREG(path_stat.st_mode)) {
+ fclose(fp);
return;
+ }
do {
r = fscanf(fp, "%x %x", ®init.address, ®init.data);
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [U-Boot] [PATCH] tools: mkimage: Call fclose in error path
2016-12-20 8:58 [U-Boot] [PATCH] tools: mkimage: Call fclose in error path Michal Simek
@ 2016-12-20 11:01 ` Ladislav Michl
2016-12-20 12:50 ` Michal Simek
2016-12-26 5:24 ` Simon Glass
2016-12-29 22:38 ` [U-Boot] " Tom Rini
2 siblings, 1 reply; 5+ messages in thread
From: Ladislav Michl @ 2016-12-20 11:01 UTC (permalink / raw)
To: u-boot
Hi Michal,
On Tue, Dec 20, 2016 at 09:58:31AM +0100, Michal Simek wrote:
> This patch is fixing missing fclose() calls
> in error patch introduced by:
> "tools: mkimage: Use fstat instead of stat to avoid malicious hacks"
> (sha1: ebe0f53f48e8f9ecc823e533a85b05c13638c350)
>
> Reported-by: Coverity (CID: 155064, 155065)
> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
> ---
>
> tools/zynqimage.c | 8 ++++++--
> tools/zynqmpimage.c | 8 ++++++--
> 2 files changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/tools/zynqimage.c b/tools/zynqimage.c
> index b47132b02a60..021d2d3fc91f 100644
> --- a/tools/zynqimage.c
> +++ b/tools/zynqimage.c
> @@ -239,11 +239,15 @@ static void zynqimage_parse_initparams(struct zynq_header *zynqhdr,
> }
>
> err = fstat(fileno(fp), &path_stat);
> - if (err)
> + if (err) {
> + fclose(fp);
> return;
> + }
>
> - if (!S_ISREG(path_stat.st_mode))
> + if (!S_ISREG(path_stat.st_mode)) {
> + fclose(fp);
> return;
> + }
>
> do {
> r = fscanf(fp, "%x %x", ®init.address, ®init.data);
> diff --git a/tools/zynqmpimage.c b/tools/zynqmpimage.c
> index 60d8ed23b4a1..0c9a3daddd6a 100644
> --- a/tools/zynqmpimage.c
> +++ b/tools/zynqmpimage.c
> @@ -251,11 +251,15 @@ static void zynqmpimage_parse_initparams(struct zynqmp_header *zynqhdr,
> }
>
> err = fstat(fileno(fp), &path_stat);
> - if (err)
> + if (err) {
> + fclose(fp);
> return;
> + }
>
> - if (!S_ISREG(path_stat.st_mode))
> + if (!S_ISREG(path_stat.st_mode)) {
> + fclose(fp);
> return;
> + }
>
> do {
> r = fscanf(fp, "%x %x", ®init.address, ®init.data);
what about something like this?
Best regards,
ladis (bored waiting for the lunch ;-))
Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
---
diff --git a/tools/zynqimage.c b/tools/zynqimage.c
index b47132b02a..026e99c00b 100644
--- a/tools/zynqimage.c
+++ b/tools/zynqimage.c
@@ -228,7 +228,7 @@ static void zynqimage_parse_initparams(struct zynq_header *zynqhdr,
FILE *fp;
struct zynq_reginit reginit;
unsigned int reg_count = 0;
- int r, err;
+ int r;
struct stat path_stat;
/* Expect a table of register-value pairs, e.g. "0x12345678 0x4321" */
@@ -238,12 +238,10 @@ static void zynqimage_parse_initparams(struct zynq_header *zynqhdr,
exit(1);
}
- err = fstat(fileno(fp), &path_stat);
- if (err)
- return;
-
- if (!S_ISREG(path_stat.st_mode))
+ if (fstat(fileno(fp), &path_stat) || !S_ISREG(path_stat.st_mode)) {
+ fclose(fp);
return;
+ }
do {
r = fscanf(fp, "%x %x", ®init.address, ®init.data);
diff --git a/tools/zynqmpimage.c b/tools/zynqmpimage.c
index 60d8ed23b4..767e93a2ab 100644
--- a/tools/zynqmpimage.c
+++ b/tools/zynqmpimage.c
@@ -240,7 +240,7 @@ static void zynqmpimage_parse_initparams(struct zynqmp_header *zynqhdr,
FILE *fp;
struct zynqmp_reginit reginit;
unsigned int reg_count = 0;
- int r, err;
+ int r;
struct stat path_stat;
/* Expect a table of register-value pairs, e.g. "0x12345678 0x4321" */
@@ -250,12 +250,10 @@ static void zynqmpimage_parse_initparams(struct zynqmp_header *zynqhdr,
exit(1);
}
- err = fstat(fileno(fp), &path_stat);
- if (err)
- return;
-
- if (!S_ISREG(path_stat.st_mode))
+ if (fstat(fileno(fp), &path_stat) || !S_ISREG(path_stat.st_mode)) {
+ fclose(fp);
return;
+ }
do {
r = fscanf(fp, "%x %x", ®init.address, ®init.data);
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [U-Boot] [PATCH] tools: mkimage: Call fclose in error path
2016-12-20 11:01 ` Ladislav Michl
@ 2016-12-20 12:50 ` Michal Simek
0 siblings, 0 replies; 5+ messages in thread
From: Michal Simek @ 2016-12-20 12:50 UTC (permalink / raw)
To: u-boot
On 20.12.2016 12:01, Ladislav Michl wrote:
> Hi Michal,
>
> On Tue, Dec 20, 2016 at 09:58:31AM +0100, Michal Simek wrote:
>> This patch is fixing missing fclose() calls
>> in error patch introduced by:
>> "tools: mkimage: Use fstat instead of stat to avoid malicious hacks"
>> (sha1: ebe0f53f48e8f9ecc823e533a85b05c13638c350)
>>
>> Reported-by: Coverity (CID: 155064, 155065)
>> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
>> ---
>>
>> tools/zynqimage.c | 8 ++++++--
>> tools/zynqmpimage.c | 8 ++++++--
>> 2 files changed, 12 insertions(+), 4 deletions(-)
>>
>> diff --git a/tools/zynqimage.c b/tools/zynqimage.c
>> index b47132b02a60..021d2d3fc91f 100644
>> --- a/tools/zynqimage.c
>> +++ b/tools/zynqimage.c
>> @@ -239,11 +239,15 @@ static void zynqimage_parse_initparams(struct zynq_header *zynqhdr,
>> }
>>
>> err = fstat(fileno(fp), &path_stat);
>> - if (err)
>> + if (err) {
>> + fclose(fp);
>> return;
>> + }
>>
>> - if (!S_ISREG(path_stat.st_mode))
>> + if (!S_ISREG(path_stat.st_mode)) {
>> + fclose(fp);
>> return;
>> + }
>>
>> do {
>> r = fscanf(fp, "%x %x", ®init.address, ®init.data);
>> diff --git a/tools/zynqmpimage.c b/tools/zynqmpimage.c
>> index 60d8ed23b4a1..0c9a3daddd6a 100644
>> --- a/tools/zynqmpimage.c
>> +++ b/tools/zynqmpimage.c
>> @@ -251,11 +251,15 @@ static void zynqmpimage_parse_initparams(struct zynqmp_header *zynqhdr,
>> }
>>
>> err = fstat(fileno(fp), &path_stat);
>> - if (err)
>> + if (err) {
>> + fclose(fp);
>> return;
>> + }
>>
>> - if (!S_ISREG(path_stat.st_mode))
>> + if (!S_ISREG(path_stat.st_mode)) {
>> + fclose(fp);
>> return;
>> + }
>>
>> do {
>> r = fscanf(fp, "%x %x", ®init.address, ®init.data);
>
> what about something like this?
Sure that will work too.
Thanks,
Michal
>
> Best regards,
> ladis (bored waiting for the lunch ;-))
>
> Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
> ---
> diff --git a/tools/zynqimage.c b/tools/zynqimage.c
> index b47132b02a..026e99c00b 100644
> --- a/tools/zynqimage.c
> +++ b/tools/zynqimage.c
> @@ -228,7 +228,7 @@ static void zynqimage_parse_initparams(struct zynq_header *zynqhdr,
> FILE *fp;
> struct zynq_reginit reginit;
> unsigned int reg_count = 0;
> - int r, err;
> + int r;
> struct stat path_stat;
>
> /* Expect a table of register-value pairs, e.g. "0x12345678 0x4321" */
> @@ -238,12 +238,10 @@ static void zynqimage_parse_initparams(struct zynq_header *zynqhdr,
> exit(1);
> }
>
> - err = fstat(fileno(fp), &path_stat);
> - if (err)
> - return;
> -
> - if (!S_ISREG(path_stat.st_mode))
> + if (fstat(fileno(fp), &path_stat) || !S_ISREG(path_stat.st_mode)) {
> + fclose(fp);
> return;
> + }
>
> do {
> r = fscanf(fp, "%x %x", ®init.address, ®init.data);
> diff --git a/tools/zynqmpimage.c b/tools/zynqmpimage.c
> index 60d8ed23b4..767e93a2ab 100644
> --- a/tools/zynqmpimage.c
> +++ b/tools/zynqmpimage.c
> @@ -240,7 +240,7 @@ static void zynqmpimage_parse_initparams(struct zynqmp_header *zynqhdr,
> FILE *fp;
> struct zynqmp_reginit reginit;
> unsigned int reg_count = 0;
> - int r, err;
> + int r;
> struct stat path_stat;
>
> /* Expect a table of register-value pairs, e.g. "0x12345678 0x4321" */
> @@ -250,12 +250,10 @@ static void zynqmpimage_parse_initparams(struct zynqmp_header *zynqhdr,
> exit(1);
> }
>
> - err = fstat(fileno(fp), &path_stat);
> - if (err)
> - return;
> -
> - if (!S_ISREG(path_stat.st_mode))
> + if (fstat(fileno(fp), &path_stat) || !S_ISREG(path_stat.st_mode)) {
> + fclose(fp);
> return;
> + }
>
> do {
> r = fscanf(fp, "%x %x", ®init.address, ®init.data);
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [U-Boot] [PATCH] tools: mkimage: Call fclose in error path
2016-12-20 8:58 [U-Boot] [PATCH] tools: mkimage: Call fclose in error path Michal Simek
2016-12-20 11:01 ` Ladislav Michl
@ 2016-12-26 5:24 ` Simon Glass
2016-12-29 22:38 ` [U-Boot] " Tom Rini
2 siblings, 0 replies; 5+ messages in thread
From: Simon Glass @ 2016-12-26 5:24 UTC (permalink / raw)
To: u-boot
On 20 December 2016 at 21:58, Michal Simek <michal.simek@xilinx.com> wrote:
> This patch is fixing missing fclose() calls
> in error patch introduced by:
> "tools: mkimage: Use fstat instead of stat to avoid malicious hacks"
> (sha1: ebe0f53f48e8f9ecc823e533a85b05c13638c350)
>
> Reported-by: Coverity (CID: 155064, 155065)
> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
> ---
>
> tools/zynqimage.c | 8 ++++++--
> tools/zynqmpimage.c | 8 ++++++--
> 2 files changed, 12 insertions(+), 4 deletions(-)
>
Reviewed-by: Simon Glass <sjg@chromium.org>
Either patch is fine.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [U-Boot] tools: mkimage: Call fclose in error path
2016-12-20 8:58 [U-Boot] [PATCH] tools: mkimage: Call fclose in error path Michal Simek
2016-12-20 11:01 ` Ladislav Michl
2016-12-26 5:24 ` Simon Glass
@ 2016-12-29 22:38 ` Tom Rini
2 siblings, 0 replies; 5+ messages in thread
From: Tom Rini @ 2016-12-29 22:38 UTC (permalink / raw)
To: u-boot
On Tue, Dec 20, 2016 at 09:58:31AM +0100, Michal Simek wrote:
> This patch is fixing missing fclose() calls
> in error patch introduced by:
> "tools: mkimage: Use fstat instead of stat to avoid malicious hacks"
> (sha1: ebe0f53f48e8f9ecc823e533a85b05c13638c350)
>
> Reported-by: Coverity (CID: 155064, 155065)
> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>
Applied to u-boot/master, thanks!
--
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20161229/864e4c31/attachment.sig>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-12-29 22:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-20 8:58 [U-Boot] [PATCH] tools: mkimage: Call fclose in error path Michal Simek
2016-12-20 11:01 ` Ladislav Michl
2016-12-20 12:50 ` Michal Simek
2016-12-26 5:24 ` Simon Glass
2016-12-29 22:38 ` [U-Boot] " Tom Rini
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.