diff options
author | Stephen Gallagher <sgallagh@redhat.com> | 2010-03-25 15:28:30 -0400 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2010-03-25 15:55:51 -0400 |
commit | e80dfd59fb89d37ba317cceb24a8c9353c70eb18 (patch) | |
tree | 857812b86424ab13b6b9ac09caa26315157cc4e3 /path_utils/path_utils.c | |
parent | 7ea74ac64811265384c8b2b2a6f12f88b63b3d95 (diff) | |
download | ding-libs-e80dfd59fb89d37ba317cceb24a8c9353c70eb18.tar.gz ding-libs-e80dfd59fb89d37ba317cceb24a8c9353c70eb18.tar.xz ding-libs-e80dfd59fb89d37ba317cceb24a8c9353c70eb18.zip |
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.
Diffstat (limited to 'path_utils/path_utils.c')
-rw-r--r-- | path_utils/path_utils.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/path_utils/path_utils.c b/path_utils/path_utils.c index 52f3650..493e0a4 100644 --- a/path_utils/path_utils.c +++ b/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 */ |