!160 lxc: fix coredump

From: @lifeng2221dd1
Reviewed-by: @duguhaotian
Signed-off-by: @duguhaotian
This commit is contained in:
openeuler-ci-bot 2021-06-15 01:54:35 +00:00 committed by Gitee
commit 2d182b76f4
3 changed files with 67 additions and 1 deletions

View File

@ -0,0 +1,57 @@
From aeb038c9f17ba6a82bb881ff6e84f0ac4c980723 Mon Sep 17 00:00:00 2001
From: LiFeng <lifeng68@huawei.com>
Date: Sat, 12 Jun 2021 13:54:25 +0800
Subject: [PATCH] coredump: fix coredump when cgroup get return error
Signed-off-by: LiFeng <lifeng68@huawei.com>
---
src/lxc/lxccontainer.c | 10 ++++++----
src/lxc/string_utils.c | 4 ++++
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index 01e6cbb69..2d581911a 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -5824,8 +5824,9 @@ static void metrics_get_blk_stats(struct lxc_container *c, struct cgroup_ops *cg
buf = malloc(len + 1);
(void)memset(buf, 0, len + 1);
ret = cgroup_ops->get(cgroup_ops, item, buf, len, c->name, c->config_path);
- if (ret != len) {
- DEBUG("get cgroup item %s len %d has changed to %d", item, len, ret);
+ if (ret <= 0) {
+ DEBUG("unable to read cgroup item %s", item);
+ goto out;
}
lines = lxc_string_split_and_trim(buf, '\n');
@@ -5880,8 +5881,9 @@ static void metrics_get_io_stats_v2(struct lxc_container *c, struct cgroup_ops *
buf = malloc(len + 1);
(void)memset(buf, 0, len + 1);
ret = cgroup_ops->get(cgroup_ops, item, buf, len, c->name, c->config_path);
- if (ret != len) {
- DEBUG("get cgroup item %s len %d change to %d", item, len, ret);
+ if (ret <= 0) {
+ DEBUG("unable to read cgroup item %s", item);
+ goto out;
}
lines = lxc_string_split_and_trim(buf, '\n');
diff --git a/src/lxc/string_utils.c b/src/lxc/string_utils.c
index 9118add02..d3c60897c 100644
--- a/src/lxc/string_utils.c
+++ b/src/lxc/string_utils.c
@@ -473,6 +473,10 @@ char **lxc_string_split_and_trim(const char *string, char _sep)
result_count++;
}
+ if (result == NULL) {
+ return calloc(1, sizeof(char *));
+ }
+
/* if we allocated too much, reduce it */
return realloc(result, (result_count + 1) * sizeof(char *));
--
2.25.1

View File

@ -1,4 +1,4 @@
%global _release 2021060101 %global _release 2021061201
Name: lxc Name: lxc
Version: 4.0.3 Version: 4.0.3
@ -33,6 +33,7 @@ Patch0022: 0022-print-error-message-if-process-workdir-failed.patch
Patch0023: 0023-log-support-long-syslog-tag.patch Patch0023: 0023-log-support-long-syslog-tag.patch
Patch0024: 0024-log-adjust-log-level-from-error-to-warn.patch Patch0024: 0024-log-adjust-log-level-from-error-to-warn.patch
Patch0025: 0025-get-cgroup-data-len-first-and-malloc-read-buff-by-le.patch Patch0025: 0025-get-cgroup-data-len-first-and-malloc-read-buff-by-le.patch
Patch0026: 0026-coredump-fix-coredump-when-cgroup-get-return-error.patch
BuildRequires: systemd-units git libtool graphviz docbook2X doxygen chrpath BuildRequires: systemd-units git libtool graphviz docbook2X doxygen chrpath
BuildRequires: pkgconfig(libseccomp) BuildRequires: pkgconfig(libseccomp)
@ -204,6 +205,12 @@ make check
%{_mandir}/*/man7/%{name}* %{_mandir}/*/man7/%{name}*
%changelog %changelog
* Sat Jun 12 2021 lifeng <lifeng68@huawei.com> - 4.0.3-2021061201
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:fix coredump
* Tue Jun 01 2021 zhangxiaoyu <zhangxiaoyu58@huawei.com> - 4.0.3-2021060101 * Tue Jun 01 2021 zhangxiaoyu <zhangxiaoyu58@huawei.com> - 4.0.3-2021060101
- Type:bugfix - Type:bugfix
- ID:NA - ID:NA

View File

@ -22,3 +22,5 @@
0022-print-error-message-if-process-workdir-failed.patch 0022-print-error-message-if-process-workdir-failed.patch
0023-log-support-long-syslog-tag.patch 0023-log-support-long-syslog-tag.patch
0024-log-adjust-log-level-from-error-to-warn.patch 0024-log-adjust-log-level-from-error-to-warn.patch
0025-get-cgroup-data-len-first-and-malloc-read-buff-by-le.patch
0026-coredump-fix-coredump-when-cgroup-get-return-error.patch