Close fp if file size is smaller than 13 bytes.

Signed-off-by: Lichen Liu <[email protected]>
---
 kexec/lzma.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/kexec/lzma.c b/kexec/lzma.c
index f27cfe2..2fc07e6 100644
--- a/kexec/lzma.c
+++ b/kexec/lzma.c
@@ -170,8 +170,11 @@ int is_lzma_file(const char *filename)
 
        const size_t size = fread(buf, 1, sizeof(buf), fp);
 
-       if (size != 13)
+       if (size != 13) {
+               /* file is too small to be a lzma file. */
+               fclose(fp);
                return 0;
+       }
 
        lzma_filter filter = { .id = LZMA_FILTER_LZMA1 };
 
-- 
2.27.0


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

Reply via email to