From 8c430d0509a2f1f5dc64de308d1c1d2668d2031b Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Wed, 4 Jun 2014 15:45:53 +0800 Subject: grub2: fix empty file handling Currently, we have a bug when parsing zero-length files: we subtract one from the length to exclude the trailing NUL (added by read_file), but a zero-length file will result in a length of -1. This change adds an explicit exit if we're attempting to parse an empty file. Signed-off-by: Jeremy Kerr --- test/parser/Makefile.am | 1 + test/parser/test-grub2-empty.c | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 test/parser/test-grub2-empty.c (limited to 'test') diff --git a/test/parser/Makefile.am b/test/parser/Makefile.am index b36889d..283b284 100644 --- a/test/parser/Makefile.am +++ b/test/parser/Makefile.am @@ -29,6 +29,7 @@ TESTS = \ test-null \ test-grub2-single \ test-grub2-default \ + test-grub2-empty \ test-grub2-default-index \ test-grub2-default-multiword \ test-grub2-multiple-resolve \ diff --git a/test/parser/test-grub2-empty.c b/test/parser/test-grub2-empty.c new file mode 100644 index 0000000..c7ebbeb --- /dev/null +++ b/test/parser/test-grub2-empty.c @@ -0,0 +1,10 @@ + +#include "parser-test.h" + +void run_test(struct parser_test *test) +{ + __test_read_conf_data(test, test->ctx->device, + "/grub2/grub.cfg", "", 0); + test_run_parser(test, "grub2"); + check_boot_option_count(test->ctx, 0); +} -- cgit v1.2.1