From bbd39bf9f0aab16069e5dfa0369742aa6afe96c0 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 26 Nov 2014 12:36:03 -0500 Subject: [PATCH] Fix: utils.c: check str*dup OOM MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- src/common/utils.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/common/utils.c b/src/common/utils.c index 1d07cb31c..203739c32 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -90,6 +90,10 @@ char *utils_partial_realpath(const char *path, char *resolved_path, size_t size) /* Cut the part we will be trying to resolve */ cut_path = strndup(path, next - path); + if (cut_path == NULL) { + PERROR("strndup"); + goto error; + } /* Try to resolve this part */ try_path = realpath((char *)cut_path, NULL); @@ -143,6 +147,10 @@ char *utils_partial_realpath(const char *path, char *resolved_path, size_t size) * path are pointers for the same memory space */ cut_path = strdup(prev); + if (cut_path == NULL) { + PERROR("strdup"); + goto error; + } /* Concatenate the strings */ snprintf(resolved_path, size, "%s%s", try_path_prev, cut_path); @@ -216,7 +224,10 @@ char *utils_expand_path(const char *path) /* We prepare the start_path not containing it */ start_path = strndup(absolute_path, next - absolute_path); - + if (!start_path) { + PERROR("strndup"); + goto error; + } /* And we concatenate it with the part after this string */ snprintf(absolute_path, PATH_MAX, "%s%s", start_path, next + 2); @@ -233,6 +244,10 @@ char *utils_expand_path(const char *path) /* Then we prepare the start_path not containing it */ start_path = strndup(absolute_path, previous - absolute_path); + if (!start_path) { + PERROR("strndup"); + goto error; + } /* And we concatenate it with the part after the '/../' */ snprintf(absolute_path, PATH_MAX, "%s%s", start_path, next + 4); -- 2.34.1