diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-08-23 13:23:58 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-08-23 13:44:13 +0200 |
commit | a38b1cbc5e917d945340a6dd9dba4274a2eb8789 (patch) | |
tree | be3a59cc2c3013c95fe5899306232dabff25c9de /lib/fstree/fstree_from_dir.c | |
parent | 029a8db2701afb0653c6e789c878bb768ceb87e1 (diff) |
Size accounting + alloc() overflow checking, round #2
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/fstree/fstree_from_dir.c')
-rw-r--r-- | lib/fstree/fstree_from_dir.c | 9 |
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; |