1 Star 0 Fork 46

jake/src-openEuler-iSulad

forked from src-openEuler/iSulad 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0019-get-the-realpath-of-the-host-path-for-archive-when-c.patch 2.31 KB
一键复制 编辑 原始数据 按行查看 历史
jake 提交于 2024-04-02 11:50 . upgrade from upstream
From 96dfd32ee5d9a133ad63af13723402f10cd7cf7b Mon Sep 17 00:00:00 2001
From: zhongtao <zhongtao17@huawei.com>
Date: Mon, 11 Mar 2024 15:50:45 +0800
Subject: [PATCH 19/43] get the realpath of the host path for archive when cp
Signed-off-by: zhongtao <zhongtao17@huawei.com>
---
src/utils/tar/isulad_tar.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/utils/tar/isulad_tar.c b/src/utils/tar/isulad_tar.c
index bbe4c3b2..fe514acc 100644
--- a/src/utils/tar/isulad_tar.c
+++ b/src/utils/tar/isulad_tar.c
@@ -390,6 +390,7 @@ int archive_copy_to(const struct io_read_wrapper *content, const struct archive_
{
int ret = -1;
struct archive_copy_info *dstinfo = NULL;
+ char cleanpath[PATH_MAX] = { 0 };
char *dstdir = NULL;
char *src_base = NULL;
char *dst_base = NULL;
@@ -410,7 +411,12 @@ int archive_copy_to(const struct io_read_wrapper *content, const struct archive_
goto cleanup;
}
- ret = archive_chroot_untar_stream(content, dstdir, ".", src_base, dst_base, root_dir, err);
+ if (realpath(dstdir, cleanpath) == NULL) {
+ ERROR("Failed to get real path for %s", dstdir);
+ return -1;
+ }
+
+ ret = archive_chroot_untar_stream(content, cleanpath, ".", src_base, dst_base, root_dir, err);
cleanup:
free_archive_copy_info(dstinfo);
@@ -428,6 +434,7 @@ static int tar_resource_rebase(const char *path, const char *rebase, const char
struct stat st;
char *srcdir = NULL;
char *srcbase = NULL;
+ char cleanpath[PATH_MAX] = { 0 };
if (lstat(path, &st) < 0) {
SYSERROR("lstat %s failed", path);
@@ -438,9 +445,14 @@ static int tar_resource_rebase(const char *path, const char *rebase, const char
ERROR("Can not split path: %s", path);
goto cleanup;
}
+
+ if (realpath(srcdir, cleanpath) == NULL) {
+ ERROR("Failed to get real path for %s", srcdir);
+ return -1;
+ }
DEBUG("chroot tar stream srcdir(%s) srcbase(%s) rebase(%s)", srcdir, srcbase, rebase);
- nret = archive_chroot_tar_stream(srcdir, srcbase, srcbase, rebase, root_dir, archive_reader);
+ nret = archive_chroot_tar_stream(cleanpath, srcbase, srcbase, rebase, root_dir, archive_reader);
if (nret < 0) {
ERROR("Can not archive path: %s", path);
goto cleanup;
--
2.34.1
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jikai11/src-openEuler-iSulad.git
git@gitee.com:jikai11/src-openEuler-iSulad.git
jikai11
src-openEuler-iSulad
src-openEuler-iSulad
master

搜索帮助