summaryrefslogtreecommitdiff
path: root/mkfs
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-11-25 13:13:05 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-11-25 13:20:08 +0100
commitfc9a644002dc501a5c224e5cc1a7dfba3ca2d1d8 (patch)
tree6fb1acf211a1bf9005236d16d22f03f8fac746d4 /mkfs
parent2d303a7f0a6076bbf5739bae4f0fa443d0da5203 (diff)
Cleanup: move overflow safe alloc code into libsquashfs
There were only a hand full of instances outside libsquashfs that used the alloc code. In most cases, the thing allocated hat its size derived from something already in memory anyway, so it is safe to assume its size fits into a size_t. At the same time, the opencoded Windows path conversion functions are all unified into a single helper function. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'mkfs')
-rw-r--r--mkfs/mkfs.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/mkfs/mkfs.c b/mkfs/mkfs.c
index 7484618..6ddcdb0 100644
--- a/mkfs/mkfs.c
+++ b/mkfs/mkfs.c
@@ -50,6 +50,7 @@ static int pack_files(sqfs_data_writer_t *data, fstree_t *fs,
const char *path;
char *node_path;
file_info_t *fi;
+ size_t size;
int ret;
if (set_working_dir(opt))
@@ -90,8 +91,16 @@ static int pack_files(sqfs_data_writer_t *data, fstree_t *fs,
if (filesize % opt->cfg.block_size)
++max_blk_count;
- inode = alloc_flex(sizeof(*inode), sizeof(sqfs_u32),
- max_blk_count);
+ if (SZ_MUL_OV(sizeof(sqfs_u32), max_blk_count, &size) ||
+ SZ_ADD_OV(sizeof(*inode), size, &size)) {
+ fputs("creating file inode: too many blocks\n",
+ stderr);
+ file->destroy(file);
+ free(node_path);
+ return -1;
+ }
+
+ inode = calloc(1, size);
if (inode == NULL) {
perror("creating file inode");
file->destroy(file);