From 2ded120a82e391c5041d1dda8297a3db7cee9109 Mon Sep 17 00:00:00 2001 From: LiFeng Date: Sat, 12 Jun 2021 14:01:17 +0800 Subject: [PATCH] lxc: fix coredump Signed-off-by: LiFeng (cherry picked from commit ea1abd3b6908af4c962f82ac56df40f46913bc06) --- ...oredump-when-cgroup-get-return-error.patch | 57 +++++++++++++++++++ lxc.spec | 9 ++- series.conf | 2 + 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 0026-coredump-fix-coredump-when-cgroup-get-return-error.patch diff --git a/0026-coredump-fix-coredump-when-cgroup-get-return-error.patch b/0026-coredump-fix-coredump-when-cgroup-get-return-error.patch new file mode 100644 index 0000000..fba43b2 --- /dev/null +++ b/0026-coredump-fix-coredump-when-cgroup-get-return-error.patch @@ -0,0 +1,57 @@ +From aeb038c9f17ba6a82bb881ff6e84f0ac4c980723 Mon Sep 17 00:00:00 2001 +From: LiFeng +Date: Sat, 12 Jun 2021 13:54:25 +0800 +Subject: [PATCH] coredump: fix coredump when cgroup get return error + +Signed-off-by: LiFeng +--- + 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 + diff --git a/lxc.spec b/lxc.spec index 3f3513f..28f1395 100644 --- a/lxc.spec +++ b/lxc.spec @@ -1,4 +1,4 @@ -%global _release 2021060101 +%global _release 2021061201 Name: lxc 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 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 +Patch0026: 0026-coredump-fix-coredump-when-cgroup-get-return-error.patch BuildRequires: systemd-units git libtool graphviz docbook2X doxygen chrpath BuildRequires: pkgconfig(libseccomp) @@ -204,6 +205,12 @@ make check %{_mandir}/*/man7/%{name}* %changelog +* Sat Jun 12 2021 lifeng - 4.0.3-2021061201 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:fix coredump + * Tue Jun 01 2021 zhangxiaoyu - 4.0.3-2021060101 - Type:bugfix - ID:NA diff --git a/series.conf b/series.conf index 7caf554..72e85e9 100644 --- a/series.conf +++ b/series.conf @@ -22,3 +22,5 @@ 0022-print-error-message-if-process-workdir-failed.patch 0023-log-support-long-syslog-tag.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 -- Gitee