diff --git a/meta/recipes-extended/procps/procps/0001-top-fix-a-fix-for-the-bye_bye-function-merge-127.patch b/meta/recipes-extended/procps/procps/0001-top-fix-a-fix-for-the-bye_bye-function-merge-127.patch new file mode 100644 index 0000000000..bbc137a3d8 --- /dev/null +++ b/meta/recipes-extended/procps/procps/0001-top-fix-a-fix-for-the-bye_bye-function-merge-127.patch @@ -0,0 +1,58 @@ +From 37f106029975e3045b0cd779525d14c55d24b74e Mon Sep 17 00:00:00 2001 +From: Jim Warner +Date: Mon, 21 Jun 2021 00:00:00 -0500 +Subject: [PATCH] top: fix a fix for the 'bye_bye' function (merge #127) + +In the merge request shown below, 1 too many bytes are +written to stdout thus including the terminating null. +As the cure, this commit just reduces the length by 1. + +[ along the way, we will remove some unneeded braces ] +[ plus add some additional comments with attribution ] + +Reference(s): +https://gitlab.com/procps-ng/procps/-/merge_requests/127 +. original merged change +commit 0bf15c004db6a3342703a3c420a5692e376c457d + +Signed-off-by: Jim Warner + +Upstream-Status: Backport [https://gitlab.com/procps-ng/procps/-/commit/37f106029975e3045b0cd779525d14c55d24b74e] + +Signed-off-by: Mingli Yu +--- + top/top.c | 14 +++++++++++--- + 1 file changed, 11 insertions(+), 3 deletions(-) + +diff --git a/top/top.c b/top/top.c +index 4d9860d5..0d21a1a5 100644 +--- a/top/top.c ++++ b/top/top.c +@@ -569,13 +569,21 @@ static void bye_bye (const char *str) { + #endif // end: OFF_HST_HASH + + numa_uninit(); ++ ++ /* we'll only have a 'str' if called by error_exit() | ++ or that xalloc_our_handler() function. if we were | ++ called from a sig_endpgm(), that parm is NULL ... | */ + if (str) { + fputs(str, stderr); + exit(EXIT_FAILURE); + } +- if (Batch) { +- write(fileno(stdout), "\n", sizeof("\n")); +- } ++ /* this could happen when called from several places | ++ including that sig_endpgm(). thus we must use an | ++ async-signal-safe write function just in case ... | ++ (thanks: Shaohua Zhan shaohua.zhan@windriver.com) | */ ++ if (Batch) ++ write(fileno(stdout), "\n", sizeof("\n") - 1); ++ + exit(EXIT_SUCCESS); + } // end: bye_bye + +-- +2.34.1 + diff --git a/meta/recipes-extended/procps/procps/0001-top-replaced-one-use-of-fputs-3-with-a-write-2-call.patch b/meta/recipes-extended/procps/procps/0001-top-replaced-one-use-of-fputs-3-with-a-write-2-call.patch new file mode 100644 index 0000000000..4da13df047 --- /dev/null +++ b/meta/recipes-extended/procps/procps/0001-top-replaced-one-use-of-fputs-3-with-a-write-2-call.patch @@ -0,0 +1,50 @@ +From 6b8980a3b6279058d727377e914cfb6439d6f178 Mon Sep 17 00:00:00 2001 +From: Shaohua Zhan +Date: Mon, 22 Mar 2021 00:00:00 +0800 +Subject: [PATCH] top: replaced one use of fputs(3) with a write(2) call + +This patch is ported from a merge request shown below, +and the following represents the original commit text. + +------------------------------------------------------ +top: In the bye_bye function, replace fputs with the write interface. + +When top calls malloc, if a signal is received, it will +call sig_endpgm to process the signal. In the bye_bye function, if the +-b option is enable, the Batch variable is set, the fputs function +will calls malloc at the same time. The malloc function is not reentrant, so +it will cause the program to crash. + +Signed-off-by: Shaohua Zhan +------------------------------------------------------ + +Reference(s): +https://gitlab.com/procps-ng/procps/-/merge_requests/127 + +Signed-off-by: Jim Warner + +Upstream-Status: Backport [https://gitlab.com/procps-ng/procps/-/commit/6b8980a3b6279058d727377e914cfb6439d6f178] + +Signed-off-by: Mingli Yu +--- + top/top.c | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/top/top.c b/top/top.c +index f4f82be4..951c240c 100644 +--- a/top/top.c ++++ b/top/top.c +@@ -417,7 +417,9 @@ static void bye_bye (const char *str) { + fputs(str, stderr); + exit(EXIT_FAILURE); + } +- if (Batch) fputs("\n", stdout); ++ if (Batch) { ++ write(fileno(stdout), "\n", sizeof("\n")); ++ } + exit(EXIT_SUCCESS); + } // end: bye_bye + +-- +2.34.1 + diff --git a/meta/recipes-extended/procps/procps_3.3.17.bb b/meta/recipes-extended/procps/procps_3.3.17.bb index bbec5a543c..131063efb9 100644 --- a/meta/recipes-extended/procps/procps_3.3.17.bb +++ b/meta/recipes-extended/procps/procps_3.3.17.bb @@ -18,6 +18,8 @@ SRC_URI = "git://gitlab.com/procps-ng/procps.git;protocol=https;branch=master \ file://0002-proc-escape.c-add-missing-include.patch \ file://CVE-2023-4016.patch \ file://CVE-2023-4016-2.patch \ + file://0001-top-replaced-one-use-of-fputs-3-with-a-write-2-call.patch \ + file://0001-top-fix-a-fix-for-the-bye_bye-function-merge-127.patch \ " SRCREV = "19a508ea121c0c4ac6d0224575a036de745eaaf8"