!451 [sync] PR-450: use ocihooks env after getenv

Merge pull request !451 from openeuler-sync-bot/sync-pr450-openEuler-22.03-LTS-to-openEuler-20.03-LTS-SP3
This commit is contained in:
haozi007 2023-03-31 06:26:00 +00:00 committed by Gitee
commit a9933eee70
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 59 additions and 1 deletions

View File

@ -0,0 +1,51 @@
From 7e515f8f42af1cdbd87442b0ea74fa934ee25576 Mon Sep 17 00:00:00 2001
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
Date: Fri, 31 Mar 2023 09:49:59 +0800
Subject: [PATCH] use ocihooks env after getenv
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
---
src/lxc/conf.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 19cf5e3..b31ba38 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -4461,7 +4461,8 @@ static char **merge_ocihook_env(char **oldenvs, size_t env_len, size_t *merge_en
{
char **result = NULL;
size_t result_len = env_len;
- size_t i, j;
+ size_t i = 0;
+ size_t j, k;
char *tmpenv = NULL;
char *lxc_envs[] = {"LD_LIBRARY_PATH", "PATH", "LXC_CGNS_AWARE", "LXC_PID", "LXC_ROOTFS_MOUNT",
"LXC_CONFIG_FILE", "LXC_CGROUP_PATH", "LXC_ROOTFS_PATH", "LXC_NAME"
@@ -4476,11 +4477,6 @@ static char **merge_ocihook_env(char **oldenvs, size_t env_len, size_t *merge_en
return NULL;
memset(result, 0, sizeof(char *) * result_len);
- for(i = 0; i < env_len; i++) {
- if (oldenvs[i])
- result[i] = safe_strdup(oldenvs[i]);
- }
-
for(j = 0; j < (sizeof(lxc_envs) / sizeof(char *)); j++) {
size_t env_buf_len = 0;
tmpenv = getenv(lxc_envs[j]);
@@ -4504,6 +4500,11 @@ static char **merge_ocihook_env(char **oldenvs, size_t env_len, size_t *merge_en
}
}
+ for(k = 0; k < env_len; k++) {
+ if (oldenvs[k] && i < (result_len - 1))
+ result[i++] = safe_strdup(oldenvs[k]);
+ }
+
*merge_env_len = i;
return result;
}
--
2.25.1

View File

@ -1,4 +1,4 @@
%global _release 2022102413
%global _release 2022102414
Name: lxc
Version: 4.0.3
@ -69,6 +69,7 @@ Patch0058: 0058-add-loongarch64-support-for-lxc.patch
Patch0059: 0059-remove-process-inheritable-capability.patch
Patch0060: 0060-check-yajl-only-when-have-isulad.patch
Patch0061: 0061-fix-ops-hierarchies-cause-coredump.patch
Patch0062: 0062-use-ocihooks-env-after-getenv.patch
BuildRequires: systemd-units git libtool graphviz docbook2X doxygen chrpath
BuildRequires: pkgconfig(libseccomp)
@ -249,6 +250,12 @@ make check
%endif
%changelog
* Fri Mar 31 2023 zhangxiaoyu<zhangxiaoyu58@huawei.com> - 4.0.3-2022102414
- Type:bugfix
- ID:NA
- SUG:NA
- DESC: use ocihooks env after getenv
* Thu Feb 23 2023 wangrunze<wangrunze13@huawei.com> - 4.0.3-2022102413
- Type:bugfix
- ID:NA