From f94abf5319d8f74cacae0a98d3925d18eb6839eb Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Thu, 25 Mar 2010 15:28:30 -0400 Subject: Fix path_utils_ut segfault In the case where the allocated buffer is not large enough to hold the resulting absolute path, we were writing out a null terminator outside of the buffer, instead of at its beginning. Also fixes potential issue where split_path would not initialize the count to zero if it returned a failure. --- common/path_utils/path_utils.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'common') diff --git a/common/path_utils/path_utils.c b/common/path_utils/path_utils.c index 52f365009..493e0a4df 100644 --- a/common/path_utils/path_utils.c +++ b/common/path_utils/path_utils.c @@ -249,13 +249,13 @@ int make_path_absolute(char *absolute_path, size_t absolute_path_size, const cha for (dst = absolute_path; *dst && dst < dst_end; dst++); if (!(path && *path)) return result; if (dst > dst_end) { - *dst = 0; + *absolute_path = 0; return ENOBUFS; } *dst++ = '/'; if (dst > dst_end) { - *dst = 0; + *absolute_path = 0; return ENOBUFS; } @@ -272,6 +272,7 @@ char **split_path(const char *path, int *count) const char *start, *end; char *mem_block, **array_ptr, *component_ptr; + if (count) *count = 0; if (!path) return NULL; /* If path is absolute add in special "/" root component */ -- cgit