Fix: possible leak of path in _utils_expand_path
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 29 Aug 2018 22:28:17 +0000 (18:28 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 30 Aug 2018 16:49:44 +0000 (12:49 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/common/utils.c

index 3f74e1fae3c21487e71e8a6aeec3be1a38558677..3442bef8922a276120e70cab43d3b46ca97ec05f 100644 (file)
@@ -197,7 +197,7 @@ error:
 }
 
 static
 }
 
 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;
 {
        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_last_char = &path[path_len];
 
        if (path_len == 0) {
-               path = NULL;
                goto error;
        }
 
                goto error;
        }
 
@@ -292,9 +291,9 @@ char *expand_double_slashes_dot_and_dotdot(char *path)
        }
 
        path[expanded_path_len] = '\0';
        }
 
        path[expanded_path_len] = '\0';
-
+       return 0;
 error:
 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 ret;
        char *absolute_path = NULL;
        char *last_token;
-       int is_dot, is_dotdot;
+       bool is_dot, is_dotdot;
 
        /* Safety net */
        if (path == NULL) {
 
        /* 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, 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;
        }
 
                goto error;
        }
 
This page took 0.027618 seconds and 5 git commands to generate.