From c538dc523893d22dbc4cddf2e8fe12fb70ea5c8f Mon Sep 17 00:00:00 2001 From: openeuler-iSula Date: Sat, 28 Dec 2019 10:15:59 +0800 Subject: [PATCH] iSulad: fix chown_network function Signed-off-by: openeuler-iSula --- .../execution/execute/execution_network.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/services/execution/execute/execution_network.c b/src/services/execution/execute/execution_network.c index 43be0fb..7c2febe 100644 --- a/src/services/execution/execute/execution_network.c +++ b/src/services/execution/execute/execution_network.c @@ -648,7 +648,6 @@ error_out: static int chown_network(const char *user_remap, const char *rootfs, const char *filename) { int ret = 0; - size_t path_len = 0; char *file_path = NULL; unsigned int host_uid = 0; unsigned int host_gid = 0; @@ -663,20 +662,9 @@ static int chown_network(const char *user_remap, const char *rootfs, const char ret = -1; goto out; } - path_len = strlen(rootfs) + strlen(filename) + 1; - if (path_len > PATH_MAX) { - ERROR("Invalid path length"); - ret = -1; - goto out; - } - file_path = util_common_calloc_s(path_len); - if (file_path == NULL) { - ERROR("Out of memory"); - ret = -1; - goto out; - } - if (sprintf_s(file_path, path_len, "%s%s", rootfs, filename) < 0) { - ERROR("Failed to print string"); + if (realpath_in_scope(rootfs, filename, &file_path) < 0) { + SYSERROR("Failed to get real path '%s' under rootfs '%s'", filename, rootfs); + lcrd_set_error_message("Failed to get real path '%s' under rootfs '%s'", filename, rootfs); ret = -1; goto out; } -- Gitee