From f0d18050d832498c8e230c04084675455fef391f Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Mon, 1 Jul 2019 11:08:20 +0200 Subject: Make sure fragment and id tables are initialized In case the tables are not completely filled by reading from the squashfs image. Bug found using scan-build. Signed-off-by: David Oberhollenzer --- lib/sqfs/frag_reader.c | 2 +- lib/sqfs/id_table_read.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sqfs/frag_reader.c b/lib/sqfs/frag_reader.c index 02d813e..0d13bcd 100644 --- a/lib/sqfs/frag_reader.c +++ b/lib/sqfs/frag_reader.c @@ -92,7 +92,7 @@ frag_reader_t *frag_reader_create(sqfs_super_t *super, int fd, if (f == NULL) goto fail_rd; - tbl = malloc(count * sizeof(tbl[0])); + tbl = calloc(count, sizeof(tbl[0])); if (tbl == NULL) goto fail_rd; diff --git a/lib/sqfs/id_table_read.c b/lib/sqfs/id_table_read.c index 6e1789d..58b0cf9 100644 --- a/lib/sqfs/id_table_read.c +++ b/lib/sqfs/id_table_read.c @@ -28,7 +28,7 @@ int id_table_read(id_table_t *tbl, int fd, sqfs_super_t *super, return -1; } - tbl->ids = malloc(super->id_count * sizeof(uint32_t)); + tbl->ids = calloc(super->id_count, sizeof(uint32_t)); if (tbl->ids == NULL) { perror("reading ID table"); return -1; -- cgit v1.2.3