diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-11-25 13:13:05 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-11-25 13:20:08 +0100 |
commit | fc9a644002dc501a5c224e5cc1a7dfba3ca2d1d8 (patch) | |
tree | 6fb1acf211a1bf9005236d16d22f03f8fac746d4 /lib/util | |
parent | 2d303a7f0a6076bbf5739bae4f0fa443d0da5203 (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 'lib/util')
-rw-r--r-- | lib/util/Makemodule.am | 2 | ||||
-rw-r--r-- | lib/util/alloc.c | 38 |
2 files changed, 1 insertions, 39 deletions
diff --git a/lib/util/Makemodule.am b/lib/util/Makemodule.am index 426e088..0ee762b 100644 --- a/lib/util/Makemodule.am +++ b/lib/util/Makemodule.am @@ -1,4 +1,4 @@ -libutil_la_SOURCES = include/util/util.h lib/util/alloc.c +libutil_la_SOURCES = include/util/util.h libutil_la_CFLAGS = $(AM_CFLAGS) libutil_la_CPPFLAGS = $(AM_CPPFLAGS) libutil_la_LDFLAGS = $(AM_LDFLAGS) diff --git a/lib/util/alloc.c b/lib/util/alloc.c deleted file mode 100644 index 526a4d5..0000000 --- a/lib/util/alloc.c +++ /dev/null @@ -1,38 +0,0 @@ -/* SPDX-License-Identifier: LGPL-3.0-or-later */ -/* - * alloc.c - * - * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> - */ -#include "config.h" - -#include "util/util.h" - -#include <stddef.h> -#include <stdlib.h> -#include <errno.h> - -void *alloc_flex(size_t base_size, size_t item_size, size_t nmemb) -{ - size_t size; - - if (SZ_MUL_OV(nmemb, item_size, &size) || - SZ_ADD_OV(base_size, size, &size)) { - errno = EOVERFLOW; - return NULL; - } - - return calloc(1, size); -} - -void *alloc_array(size_t item_size, size_t nmemb) -{ - size_t size; - - if (SZ_MUL_OV(nmemb, item_size, &size)) { - errno = EOVERFLOW; - return NULL; - } - - return calloc(1, size); -} |