aboutsummaryrefslogtreecommitdiff
path: root/lib/fstree/fstree_from_dir.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/fstree/fstree_from_dir.c')
-rw-r--r--lib/fstree/fstree_from_dir.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/fstree/fstree_from_dir.c b/lib/fstree/fstree_from_dir.c
index 9aab5df..d6fac86 100644
--- a/lib/fstree/fstree_from_dir.c
+++ b/lib/fstree/fstree_from_dir.c
@@ -25,6 +25,7 @@
static char *get_file_path(tree_node_t *n, const char *name)
{
char *ptr, *new;
+ size_t len;
int ret;
if (n->parent == NULL) {
@@ -41,7 +42,13 @@ static char *get_file_path(tree_node_t *n, const char *name)
ret = canonicalize_name(ptr);
assert(ret == 0);
- new = realloc(ptr, strlen(ptr) + strlen(name) + 2);
+ if (SZ_ADD_OV(strlen(ptr), strlen(name), &len) ||
+ SZ_ADD_OV(len, 2, &len)) {
+ errno = EOVERFLOW;
+ goto fail;
+ }
+
+ new = realloc(ptr, len);
if (new == NULL)
goto fail;