From a5045bf07b11efba386cbaec492f6ad6e6553032 Mon Sep 17 00:00:00 2001 From: EulerOSWander <314264452@qq.com> Date: Mon, 26 Jun 2023 19:32:25 +0800 Subject: [PATCH] pmap: increase memory allocation failure judgment --- ...e-memory-allocation-failure-judgment.patch | 41 +++++++++++++++++++ procps-ng.spec | 6 ++- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 backport-pmap-Increase-memory-allocation-failure-judgment.patch diff --git a/backport-pmap-Increase-memory-allocation-failure-judgment.patch b/backport-pmap-Increase-memory-allocation-failure-judgment.patch new file mode 100644 index 0000000..6ca63c3 --- /dev/null +++ b/backport-pmap-Increase-memory-allocation-failure-judgment.patch @@ -0,0 +1,41 @@ +From b51ef773ad5cbd3eb9e348df4f70eb03307ce044 Mon Sep 17 00:00:00 2001 +From: EulerOSWander <314264452@qq.com> +Date: Mon, 12 Jun 2023 14:19:30 +0800 +Subject: [PATCH] pmap: Increase memory allocation failure judgment + +Call trace: + #0 __vsnprintf_internal + #1 0x00007f967aedd656 in __GI___snprintf + #2 0x00005612da28c707 in snprintf + #3 config_read (rc_filename=) at pmap.c:885 + #4 0x00005612da28b8c0 int main at pmap.c:1144 + +The above stack is caused by calling a null pointer +after the memory allocation fails. Increase the null +pointer judgment. + +signed-off-by: zhoujie +--- + src/pmap.c | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/src/pmap.c b/src/pmap.c +index 658b2501..74d57dab 100644 +--- a/src/pmap.c ++++ b/src/pmap.c +@@ -881,7 +881,11 @@ static int config_read (char *rc_filename) + } + + /* add the field in the list */ +- cnf_listnode = calloc(1, sizeof *cnf_listnode); ++ if (!(cnf_listnode = calloc(1, sizeof *cnf_listnode))) { ++ xwarnx(_("memory allocation failed")); ++ fclose(f); ++ return 0; ++ } + snprintf(cnf_listnode -> description, sizeof(cnf_listnode -> description), "%s", token); + cnf_listnode -> next = cnf_listhead; + cnf_listhead = cnf_listnode; +-- +2.33.0 + diff --git a/procps-ng.spec b/procps-ng.spec index fcb3c95..dd0fd00 100644 --- a/procps-ng.spec +++ b/procps-ng.spec @@ -1,6 +1,6 @@ Name: procps-ng Version: 4.0.2 -Release: 4 +Release: 5 Summary: Utilities that provide system information. License: GPL+ and GPLv2 and GPLv2+ and GPLv3+ and LGPLv2+ URL: https://sourceforge.net/projects/procps-ng/ @@ -16,6 +16,7 @@ Patch4: backport-top-address-the-missing-guest-tics-for-summary-area.patch Patch5: backport-0001-ps-address-missing-or-corrupted-fields-with-m-option.patch Patch6: backport-0002-ps-trade-previous-fix-for-final-solution-to-m-option.patch Patch7: backport-top-lessen-summary-cpu-distortions-with-first-displa.patch +Patch8: backport-pmap-Increase-memory-allocation-failure-judgment.patch BuildRequires: ncurses-devel libtool autoconf automake gcc gettext-devel systemd-devel systemd-pam @@ -98,6 +99,9 @@ ln -s %{_bindir}/pidof %{buildroot}%{_sbindir}/pidof %{_mandir}/man* %changelog +* Mon Jun 26 2023 zhoujie - 4.0.2-5 +- pmap: increase memory allocation failure judgment + * Tue Jun 13 2023 zhoujie - 4.0.2-4 - top: first time display delay -- Gitee