From f5c0f0c75181d5e7fa56d11fa59a32a1c088020a Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Mon, 26 Aug 2019 09:13:59 +0200 Subject: Tune the paranoia down a bit size_t is guaranteed to be large enough to measure the size of things in memory, so when doing exactely that (e.g. strlen(a) + strlen(b)), checking for overflow is pointless since both objects are already in memory. If the addition would overflow, the two strings would occupy more memory than addressable. (Possible exception being some kind of harward style architecture with the two strings being in different kinds of memory of course.) Signed-off-by: David Oberhollenzer --- lib/fstree/get_path.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'lib/fstree/get_path.c') diff --git a/lib/fstree/get_path.c b/lib/fstree/get_path.c index f464ade..decf92e 100644 --- a/lib/fstree/get_path.c +++ b/lib/fstree/get_path.c @@ -7,11 +7,9 @@ #include "config.h" #include "fstree.h" -#include "util.h" #include #include -#include char *fstree_get_path(tree_node_t *node) { @@ -23,19 +21,14 @@ char *fstree_get_path(tree_node_t *node) return strdup("/"); for (it = node; it != NULL && it->parent != NULL; it = it->parent) { - if (SZ_ADD_OV(len, strlen(it->name), &len) || - SZ_ADD_OV(len, 1, &len)) - goto fail_ov; + len += strlen(it->name) + 1; } - if (SZ_ADD_OV(len, 1, &len)) - goto fail_ov; - - str = malloc(len); + str = malloc(len + 1); if (str == NULL) return NULL; - ptr = str + len - 1; + ptr = str + len; *ptr = '\0'; for (it = node; it != NULL && it->parent != NULL; it = it->parent) { @@ -47,7 +40,4 @@ char *fstree_get_path(tree_node_t *node) } return str; -fail_ov: - errno = EOVERFLOW; - return NULL; } -- cgit v1.2.3