From 8ebaefd7120425d88f389b28398e7bbfd192f009 Mon Sep 17 00:00:00 2001 From: Nathan Fisher Date: Tue, 25 Jul 2023 19:50:46 -0400 Subject: [PATCH] Check for NULL after allocating --- src/haggis.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/haggis.c b/src/haggis.c index 31e6974..2eb31fc 100644 --- a/src/haggis.c +++ b/src/haggis.c @@ -247,6 +247,8 @@ int haggis_load_file(FILE *stream, union haggis_ft *ft) { if (haggis_load_cksum(stream, ft->file->cksum) != 0) return 1; u8 *data = malloc((size_t)len.val); + if (data == NULL) + return -1; int res = fread(data, 1, (size_t)ft->file->len.val, stream); if (res != (size_t)ft->file->len.val) { free(ft); @@ -333,6 +335,8 @@ int haggis_load_filename(FILE *stream, struct haggis_filename *n) { return 2; n->len = len; name = malloc((size_t)len.val); + if (name == NULL) + return -1; if (fread(name, 1, (size_t)len.val, stream) != (size_t)len.val) { free(name); return 2; @@ -383,6 +387,8 @@ enum haggis_typeflag haggis_filetype_from_mode(union u16 mode) { struct haggis_node* haggis_create_node(char *file) { struct haggis_node *node = malloc(sizeof(struct haggis_node)); + if (node == NULL) + return NULL; // todo return node; }