Check if file size is not zero and check the return value of close() as it might fail, though it's very unlikely.
Signed-off-by: Ralf Ramsauer <[email protected]> --- tools/jailhouse.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/jailhouse.c b/tools/jailhouse.c index 5bf9b0f..8c7783c 100644 --- a/tools/jailhouse.c +++ b/tools/jailhouse.c @@ -156,6 +156,11 @@ static void *read_file(const char *name, size_t *size) exit(1); } + if (stat.st_size == 0) { + fprintf(stderr, "reading empty file: %s\n", name); + exit(1); + } + buffer = malloc(stat.st_size); if (!buffer) { fprintf(stderr, "insufficient memory\n"); @@ -167,7 +172,10 @@ static void *read_file(const char *name, size_t *size) exit(1); } - close(fd); + if (close(fd)) { + fprintf(stderr, "closing %s: %s\n", name, strerror(errno)); + exit(1); + } if (size) *size = stat.st_size; -- 2.9.2 -- You received this message because you are subscribed to the Google Groups "Jailhouse" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
