fuzz/x86_emulate: Fix afl-harness batch mode file pointer leak
PATCH 1/1 fuzz/x86_emulate: Fix afl-harness batch mode file pointer leak
Changeset XXXX introduced "batch mode" to afl-harness, which allowed the handling of several inputs in sequence.
Unfortunately, it introduced a file pointer leak when the file was larger than the maximum size. Restructure the code to always close fp if we opened it.
---
Release exception justification:
- This is a bug fix. The problem is relatively minor, but the fix is relatively minor too.
--- tools/fuzz/x86_instruction_emulator/afl-harness.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
tools/fuzz/x86_instruction_emulator/afl-harness.c +6 -4
@@ -99,13 +99,17 @@ int main(int argc, char **argv)exit (-1 ); } -if ( !feof (fp) ) +/* Only run the test if the input file was smaller than INPUT_SIZE */ +if (feof (fp) ) + { +LLVMFuzzerTestOneInput (input, size); + } +else {printf ("Input too large\n" );/* Don't exit if we're doing batch processing */ if ( max ==1 )exit (-1 ); -continue ; }if ( fp != stdin )
@@ -113,8 +117,6 @@ int main(int argc, char **argv)fclose (fp); fp =NULL ; } - -LLVMFuzzerTestOneInput (input, size); }return 0 ;
Signature · 7 lines
2.14.2 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 13.10.17 at 11:00, <[email protected]> wrote:
Changeset XXXX introduced "batch mode" to afl-harness, which allowed
With (part of) the commit hash and the title inserted here and ...
tools/fuzz/x86_instruction_emulator/afl-harness.c int main(int argc, char **argv) · line 106
Quoted 12 lines
tools/fuzz/x86_instruction_emulator/afl-harness.c +5
-1@@ -99,13 +99,17 @@ int main(int argc, char **argv)exit (-1 ); } -if ( !feof (fp) ) +/* Only run the test if the input file was smaller than INPUT_SIZE */ +if (feof (fp) ) + { +LLVMFuzzerTestOneInput (input, size); + }
... ideally with the unnecessary braces dropped here
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 4 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 13.10.17 at 11:00, <[email protected]> wrote:
Changeset XXXX introduced "batch mode" to afl-harness, which allowed
With (part of) the commit hash and the title inserted here and ...
Gah. :-)
Quoted 15 lines
tools/fuzz/x86_instruction_emulator/afl-harness.c int main(int argc, char **argv) · line 106
Quoted 13 lines
tools/fuzz/x86_instruction_emulator/afl-harness.c +5
-1@@ -99,13 +99,17 @@ int main(int argc, char **argv)exit (-1 ); } -if ( !feof (fp) ) +/* Only run the test if the input file was smaller than INPUT_SIZE */ +if (feof (fp) ) + { +LLVMFuzzerTestOneInput (input, size); + }... ideally with the unnecessary braces dropped here
Quoted 1 line
Reviewed-by Jan Beulich <[email protected]>
Do you really want this to look like this?
if ( ... )
foo();
else
{
...
}
-George
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 13.10.17 at 11:10, <[email protected]> wrote:
Quoted 15 lines · Jan Beulich
tools/fuzz/x86_instruction_emulator/afl-harness.c int main(int argc, char **argv) · line 106
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 13.10.17 at 11:00, <[email protected]> wrote:
tools/fuzz/x86_instruction_emulator/afl-harness.c +5
-1@@ -99,13 +99,17 @@ int main(int argc, char **argv)exit (-1 ); } -if ( !feof (fp) ) +/* Only run the test if the input file was smaller than INPUT_SIZE */ +if (feof (fp) ) + { +LLVMFuzzerTestOneInput (input, size); + }... ideally with the unnecessary braces dropped here
Quoted 1 line
Reviewed-by Jan Beulich <[email protected]>
Quoted 8 lines
Do you really want this to look like this?
if ( ... )
foo();
else{ ... }
Yes. It's Linux and qemu who dislike non-matched if/else bodies, but our ./CODING_STYLE only says
"Braces should be omitted for blocks with a single statement. e.g.,
if ( condition )
single_statement();"
and personally I'm happy that it doesn't say anything more.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 31 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 13.10.17 at 11:10, <[email protected]> wrote:
Quoted 15 lines · Jan Beulich
tools/fuzz/x86_instruction_emulator/afl-harness.c int main(int argc, char **argv) · line 106
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 13.10.17 at 11:00, <[email protected]> wrote:
tools/fuzz/x86_instruction_emulator/afl-harness.c +5
-1@@ -99,13 +99,17 @@ int main(int argc, char **argv)exit (-1 ); } -if ( !feof (fp) ) +/* Only run the test if the input file was smaller than INPUT_SIZE */ +if (feof (fp) ) + { +LLVMFuzzerTestOneInput (input, size); + }... ideally with the unnecessary braces dropped here
Quoted 1 line
Reviewed-by Jan Beulich <[email protected]>Quoted 8 lines
Do you really want this to look like this?
if ( ... )
foo();
else{ ... }Yes. It's Linux and qemu who dislike non-matched if/else bodies, but our ./CODING_STYLE only says
Quoted 6 lines
"Braces should be omitted for blocks with a single statement. e.g.,
if ( condition )
single_statement();"and personally I'm happy that it doesn't say anything more.
Hmm, I personally think it's ugly enough that I'd rather restructure the code to avoid it looking like that. :-)
I'll see what I can do.
-George
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 38 lines
Quoted 1 line
Quoted 1 line · On 13.10.17 at 12:23, <[email protected]> wrote:
Quoted 36 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 13.10.17 at 11:10, <[email protected]> wrote:
Quoted 15 lines · Jan Beulich
tools/fuzz/x86_instruction_emulator/afl-harness.c int main(int argc, char **argv) · line 106
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 13.10.17 at 11:00, <[email protected]> wrote:
tools/fuzz/x86_instruction_emulator/afl-harness.c +5
-1@@ -99,13 +99,17 @@ int main(int argc, char **argv)exit (-1 ); } -if ( !feof (fp) ) +/* Only run the test if the input file was smaller than INPUT_SIZE */ +if (feof (fp) ) + { +LLVMFuzzerTestOneInput (input, size); + }... ideally with the unnecessary braces dropped here
Quoted 1 line
Reviewed-by Jan Beulich <[email protected]>Quoted 8 lines
Do you really want this to look like this?
if ( ... )
foo();
else{ ... }Yes. It's Linux and qemu who dislike non-matched if/else bodies, but our ./CODING_STYLE only says
"Braces should be omitted for blocks with a single statement. e.g.,
if ( condition )
single_statement();"
Quoted 6 lines
Quoted 1 line
and personally I'm happy that it doesn't say anything more.
Hmm, I personally think it's ugly enough that I'd rather restructure the code to avoid it looking like that. :-)
I'll see what I can do.
Well, assuming you would think that way I've intentionally said "ideally", i.e. if you really don't want to change it, I can live with the braces.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 40 lines · Jan Beulich
Quoted 40 lines
Quoted 1 line
Quoted 1 line · On 13.10.17 at 12:23, <[email protected]> wrote:
Quoted 37 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 13.10.17 at 11:10, <[email protected]> wrote:
Quoted 15 lines · Jan Beulich
tools/fuzz/x86_instruction_emulator/afl-harness.c int main(int argc, char **argv) · line 106
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 13.10.17 at 11:00, <[email protected]> wrote:
tools/fuzz/x86_instruction_emulator/afl-harness.c +5
-1@@ -99,13 +99,17 @@ int main(int argc, char **argv)exit (-1 ); } -if ( !feof (fp) ) +/* Only run the test if the input file was smaller than INPUT_SIZE */ +if (feof (fp) ) + { +LLVMFuzzerTestOneInput (input, size); + }... ideally with the unnecessary braces dropped here
Quoted 1 line
Reviewed-by Jan Beulich <[email protected]>Quoted 8 lines
Do you really want this to look like this?
if ( ... )
foo();
else{ ... }Yes. It's Linux and qemu who dislike non-matched if/else bodies, but our ./CODING_STYLE only says
"Braces should be omitted for blocks with a single statement. e.g.,
if ( condition )
single_statement();"and personally I'm happy that it doesn't say anything more.
Quoted 8 lines
Quoted 4 lines
Hmm, I personally think it's ugly enough that I'd rather restructure the code to avoid it looking like that. :-)
I'll see what I can do.
Well, assuming you would think that way I've intentionally said "ideally", i.e. if you really don't want to change it, I can live with the braces.
OK, thanks. :-)
-George
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 4 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 13.10.17 at 11:00, <[email protected]> wrote:
Changeset XXXX introduced "batch mode" to afl-harness, which allowed
With (part of) the commit hash and the title inserted here and ...
This should be 2b1cde7783 BTW.
-George
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Hi George,
Quoted 11 lines · George Dunlap
Changeset XXXX introduced "batch mode" to afl-harness, which allowed the handling of several inputs in sequence.
Unfortunately, it introduced a file pointer leak when the file was larger than the maximum size. Restructure the code to always close fp if we opened it.
Signed-off-by George Dunlap <[email protected]>---
Release exception justification:
- This is a bug fix. The problem is relatively minor, but the fix is relatively minor too.
I agree here:
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel