From 6740483e83db41dc811871d5b0689f39f23df122 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 29 Aug 2018 18:28:17 -0400 Subject: [PATCH] Fix: possible leak of path in _utils_expand_path MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- src/common/utils.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) 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; } -- 2.34.1