From: Jérémie Galarneau Date: Wed, 29 Aug 2018 22:28:17 +0000 (-0400) Subject: Fix: possible leak of path in _utils_expand_path X-Git-Tag: v2.11.0-rc1~26 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=6740483e83db41dc811871d5b0689f39f23df122;p=lttng-tools.git Fix: possible leak of path in _utils_expand_path Signed-off-by: Jérémie Galarneau --- diff --git a/src/common/utils.c b/src/common/utils.c index 3f74e1fae..3442bef89 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -197,7 +197,7 @@ error: } static -char *expand_double_slashes_dot_and_dotdot(char *path) +int expand_double_slashes_dot_and_dotdot(char *path) { size_t expanded_path_len, path_len; const char *curr_char, *path_last_char, *next_slash, *prev_slash; @@ -206,7 +206,6 @@ char *expand_double_slashes_dot_and_dotdot(char *path) path_last_char = &path[path_len]; if (path_len == 0) { - path = NULL; goto error; } @@ -292,9 +291,9 @@ char *expand_double_slashes_dot_and_dotdot(char *path) } path[expanded_path_len] = '\0'; - + return 0; error: - return path; + return -1; } /* @@ -313,7 +312,7 @@ char *_utils_expand_path(const char *path, bool keep_symlink) int ret; char *absolute_path = NULL; char *last_token; - int is_dot, is_dotdot; + bool is_dot, is_dotdot; /* Safety net */ if (path == NULL) { @@ -364,8 +363,8 @@ char *_utils_expand_path(const char *path, bool keep_symlink) absolute_path, LTTNG_PATH_MAX); } - absolute_path = expand_double_slashes_dot_and_dotdot(absolute_path); - if (!absolute_path) { + ret = expand_double_slashes_dot_and_dotdot(absolute_path); + if (ret) { goto error; }