提交 9da9d817 编写于 作者: L LiFeng

iSulad: internal change in read user file

Signed-off-by: NLiFeng <lifeng68@huawei.com>
上级 47b8d809
...@@ -468,34 +468,35 @@ out: ...@@ -468,34 +468,35 @@ out:
static int read_user_file(const char *basefs, const char *user_path, FILE **stream) static int read_user_file(const char *basefs, const char *user_path, FILE **stream)
{ {
int nret; int ret = 0;
int64_t filesize = 0; int64_t filesize = 0;
char path[PATH_MAX] = {0}; char *real_path = NULL;
char real_path[PATH_MAX] = {0};
nret = snprintf(path, sizeof(path), "%s/%s", basefs, user_path); if (realpath_in_scope(basefs, user_path, &real_path) < 0) {
if (nret < 0 || (size_t)nret >= sizeof(path)) { ERROR("user target file '%s' real path must be under '%s'", user_path, basefs);
ERROR("Path is too long"); lcrd_set_error_message("user target file '%s' real path must be under '%s'", user_path, basefs);
return -1; ret = -1;
} goto out;
if (cleanpath(path, real_path, sizeof(real_path)) == NULL) {
ERROR("Failed to clean path");
return -1;
} }
filesize = util_file_size(real_path); filesize = util_file_size(real_path);
if (filesize > REGULAR_FILE_SIZE) { if (filesize > REGULAR_FILE_SIZE) {
ERROR("File %s is more than %lld", real_path, (long long)REGULAR_FILE_SIZE); ERROR("File %s is more than %lld", real_path, (long long)REGULAR_FILE_SIZE);
lcrd_set_error_message("File %s is more than %lld", real_path, (long long)REGULAR_FILE_SIZE); lcrd_set_error_message("File %s is more than %lld", real_path, (long long)REGULAR_FILE_SIZE);
return -1; ret = -1;
goto out;
} }
*stream = util_fopen(real_path, "r"); *stream = util_fopen(real_path, "r");
if (*stream == NULL) { if (*stream == NULL) {
ERROR("Failed to open %s: %s", real_path, strerror(errno)); ERROR("Failed to open %s: %s", real_path, strerror(errno));
return 0; ret = 0;
goto out;
} }
return 0;
out:
free(real_path);
return ret;
} }
static void parse_user_group(const char *username, char **user, char **group, char **tmp_dup) static void parse_user_group(const char *username, char **user, char **group, char **tmp_dup)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册