2011-02-23 01:34:00

by Daniel J Blueman

[permalink] [raw]
Subject: [2.6.38-rc6] build:mkpiggy fixlet...

Ensure build doesn't silently continue despite read failure,
addressing a warning due to the unchecked call.

Signed-off-by: Daniel J Blueman <[email protected]>

diff --git a/arch/x86/boot/compressed/mkpiggy.c
b/arch/x86/boot/compressed/mkpiggy.c
index 646aa78..845a1f8 100644
--- a/arch/x86/boot/compressed/mkpiggy.c
+++ b/arch/x86/boot/compressed/mkpiggy.c
@@ -62,7 +62,12 @@ int main(int argc, char *argv[])
if (fseek(f, -4L, SEEK_END)) {
perror(argv[1]);
}
- fread(&olen, sizeof olen, 1, f);
+
+ if (fread(&olen, sizeof(olen), 1, f) != 1) {
+ perror(argv[1]);
+ return 1;
+ }
+
ilen = ftell(f);
olen = getle32(&olen);
fclose(f);
--
Daniel J Blueman


2011-02-28 16:26:12

by Cong Wang

[permalink] [raw]
Subject: Re: [2.6.38-rc6] build:mkpiggy fixlet...

On Wed, Feb 23, 2011 at 09:33:59AM +0800, Daniel J Blueman wrote:
>Ensure build doesn't silently continue despite read failure,
>addressing a warning due to the unchecked call.
>
>Signed-off-by: Daniel J Blueman <[email protected]>
>
>diff --git a/arch/x86/boot/compressed/mkpiggy.c
>b/arch/x86/boot/compressed/mkpiggy.c
>index 646aa78..845a1f8 100644
>--- a/arch/x86/boot/compressed/mkpiggy.c
>+++ b/arch/x86/boot/compressed/mkpiggy.c
>@@ -62,7 +62,12 @@ int main(int argc, char *argv[])
> if (fseek(f, -4L, SEEK_END)) {
> perror(argv[1]);
> }
>- fread(&olen, sizeof olen, 1, f);
>+
>+ if (fread(&olen, sizeof(olen), 1, f) != 1) {
>+ perror(argv[1]);
>+ return 1;


You need to close the file here...


>+ }
>+
> ilen = ftell(f);
> olen = getle32(&olen);
> fclose(f);

Thanks.

2011-03-01 01:52:30

by Daniel J Blueman

[permalink] [raw]
Subject: Re: [2.6.38-rc6] build:mkpiggy fixlet...

On 1 March 2011 00:25, Am?rico Wang <[email protected]> wrote:
> On Wed, Feb 23, 2011 at 09:33:59AM +0800, Daniel J Blueman wrote:
>>Ensure build doesn't silently continue despite read failure,
>>addressing a warning due to the unchecked call.
>>
>>Signed-off-by: Daniel J Blueman <[email protected]>
>>
>>diff --git a/arch/x86/boot/compressed/mkpiggy.c
>>b/arch/x86/boot/compressed/mkpiggy.c
>>index 646aa78..845a1f8 100644
>>--- a/arch/x86/boot/compressed/mkpiggy.c
>>+++ b/arch/x86/boot/compressed/mkpiggy.c
>>@@ -62,7 +62,12 @@ int main(int argc, char *argv[])
>> ? ? ? if (fseek(f, -4L, SEEK_END)) {
>> ? ? ? ? ? ? ? perror(argv[1]);
>> ? ? ? }
>>- ? ? ?fread(&olen, sizeof olen, 1, f);
>>+
>>+ ? ? ?if (fread(&olen, sizeof(olen), 1, f) != 1) {
>>+ ? ? ? ? ? ? ?perror(argv[1]);
>>+ ? ? ? ? ? ? ?return 1;
>
> You need to close the file here...

I could close the file here to be polite, but since the program is
exiting, the OS will close the file.

I added the error path in a way consistent with the following error
path - perhaps better than a more intrusive patch to handle everything
gracefully; it just fixes the bug (ie silent failure) and isn't a
cleanup.

>>+ ? ? ?}
>>+
>> ? ? ? ilen = ftell(f);
>> ? ? ? olen = getle32(&olen);
>> ? ? ? fclose(f);
--
Daniel J Blueman

2011-03-02 00:43:24

by Daniel J Blueman

[permalink] [raw]
Subject: [tip:x86/urgent] x86, build: Make sure mkpiggy fails on read error

Commit-ID: 6670e9cdaf554290e26121aa72f0118f2fac52e5
Gitweb: http://git.kernel.org/tip/6670e9cdaf554290e26121aa72f0118f2fac52e5
Author: Daniel J Blueman <[email protected]>
AuthorDate: Wed, 23 Feb 2011 09:33:59 +0800
Committer: H. Peter Anvin <[email protected]>
CommitDate: Tue, 1 Mar 2011 16:32:03 -0800

x86, build: Make sure mkpiggy fails on read error

Ensure build doesn't silently continue despite read failure,
addressing a warning due to the unchecked call.

Signed-off-by: Daniel J Blueman <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: H. Peter Anvin <[email protected]>
---
arch/x86/boot/compressed/mkpiggy.c | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/arch/x86/boot/compressed/mkpiggy.c b/arch/x86/boot/compressed/mkpiggy.c
index 646aa78..46a8238 100644
--- a/arch/x86/boot/compressed/mkpiggy.c
+++ b/arch/x86/boot/compressed/mkpiggy.c
@@ -62,7 +62,12 @@ int main(int argc, char *argv[])
if (fseek(f, -4L, SEEK_END)) {
perror(argv[1]);
}
- fread(&olen, sizeof olen, 1, f);
+
+ if (fread(&olen, sizeof(olen), 1, f) != 1) {
+ perror(argv[1]);
+ return 1;
+ }
+
ilen = ftell(f);
olen = getle32(&olen);
fclose(f);