From d7c23421dddd4dcfbdfd329299816fa7d020eeb8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Mon, 19 Oct 2015 17:37:27 -0400 Subject: [PATCH] Port: Explicitly allocate realpath() resolved buffer 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, 12 insertions(+), 1 deletion(-) diff --git a/src/common/utils.c b/src/common/utils.c index 11018739b..2417a7d25 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "utils.h" #include "defaults.h" @@ -81,6 +82,8 @@ char *utils_partial_realpath(const char *path, char *resolved_path, size_t size) /* Resolve the canonical path of the first part of the path */ while (try_path != NULL && next != end) { + char *try_path_buf = NULL; + /* * If there is not any '/' left, we want to try with * the full path @@ -97,9 +100,16 @@ char *utils_partial_realpath(const char *path, char *resolved_path, size_t size) goto error; } + try_path_buf = zmalloc(LTTNG_PATH_MAX); + if (!try_path_buf) { + PERROR("zmalloc"); + goto error; + } + /* Try to resolve this part */ - try_path = realpath((char *)cut_path, NULL); + try_path = realpath((char *)cut_path, try_path_buf); if (try_path == NULL) { + free(try_path_buf); /* * There was an error, we just want to be assured it * is linked to an unexistent directory, if it's another @@ -116,6 +126,7 @@ char *utils_partial_realpath(const char *path, char *resolved_path, size_t size) } } else { /* Save the place we are before trying the next step */ + try_path_buf = NULL; free(try_path_prev); try_path_prev = try_path; prev = next; -- 2.34.1