From ef9c210ed651b60b96a3464518ff2d26abc20644 Mon Sep 17 00:00:00 2001 From: 19909236985 Date: Tue, 3 Nov 2020 14:21:18 +0800 Subject: [PATCH] sync patchs --- ...crash-on-missing-proc-xxxx-directory.patch | 32 ++++++ ...l-for-do-not-crash-on-missing-proces.patch | 33 ++++++ ...003-killall-minor-str-length-changes.patch | 41 +++++++ backport-0004-pstree-minor-snprintf-fix.patch | 38 +++++++ ...-peekfd-Check-return-value-of-malloc.patch | 32 ++++++ ...-fuser-free-local-port-before-return.patch | 46 ++++++++ backport-0007-peekfd-exit-after-perror.patch | 29 +++++ ...ve-NULs-in-cmdline-args-wrongly-pars.patch | 31 +++++ ...Less-confused-about-duplicate-dev_id.patch | 107 ++++++++++++++++++ ...k-pathname-only-on-non-block-devices.patch | 56 +++++++++ psmisc.spec | 16 ++- 11 files changed, 460 insertions(+), 1 deletion(-) create mode 100644 backport-0001-pstree-do-not-crash-on-missing-proc-xxxx-directory.patch create mode 100644 backport-0002-pstree-additional-for-do-not-crash-on-missing-proces.patch create mode 100644 backport-0003-killall-minor-str-length-changes.patch create mode 100644 backport-0004-pstree-minor-snprintf-fix.patch create mode 100644 backport-0005-peekfd-Check-return-value-of-malloc.patch create mode 100644 backport-0006-fuser-free-local-port-before-return.patch create mode 100644 backport-0007-peekfd-exit-after-perror.patch create mode 100644 backport-0008-pstree-consecutive-NULs-in-cmdline-args-wrongly-pars.patch create mode 100644 backport-0009-fuser-Less-confused-about-duplicate-dev_id.patch create mode 100644 backport-0010-fuser-Check-pathname-only-on-non-block-devices.patch diff --git a/backport-0001-pstree-do-not-crash-on-missing-proc-xxxx-directory.patch b/backport-0001-pstree-do-not-crash-on-missing-proc-xxxx-directory.patch new file mode 100644 index 0000000..3715a0c --- /dev/null +++ b/backport-0001-pstree-do-not-crash-on-missing-proc-xxxx-directory.patch @@ -0,0 +1,32 @@ +From d21bee476432e0d0442662fa7899d4dd4897e097 Mon Sep 17 00:00:00 2001 +From: Piotr Praszmo +Date: Wed, 23 Oct 2019 14:11:01 +0200 +Subject: [PATCH 46/65] pstree: do not crash on missing /proc/xxxx directory + +This can happen when process ends while pstree is running. +Ignore such processes. + +https://gitlab.com/psmisc/psmisc/-/commit/d21bee476432e0d0442662fa7899d4dd4897e097 +--- + src/pstree.c | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +diff --git a/src/pstree.c b/src/pstree.c +index 99881e9..3de0792 100644 +--- a/src/pstree.c ++++ b/src/pstree.c +@@ -1035,8 +1035,9 @@ static void read_proc(void) + } + #endif /*WITH_SELINUX */ + if (stat(path, &st) < 0) { +- perror(path); +- exit(1); ++ (void) fclose(file); ++ free(path); ++ continue; + } + size = fread(readbuf, 1, BUFSIZ, file); + if (ferror(file) == 0) { +-- +2.22.0.windows.1 + diff --git a/backport-0002-pstree-additional-for-do-not-crash-on-missing-proces.patch b/backport-0002-pstree-additional-for-do-not-crash-on-missing-proces.patch new file mode 100644 index 0000000..8071e8b --- /dev/null +++ b/backport-0002-pstree-additional-for-do-not-crash-on-missing-proces.patch @@ -0,0 +1,33 @@ +From b6c2b1288bd99f52d962301a2e41a0102d2a2d35 Mon Sep 17 00:00:00 2001 +From: Craig Small +Date: Fri, 15 Nov 2019 09:53:12 +1100 +Subject: [PATCH 47/65] pstree: additional for do not crash on missing + processes + +https://gitlab.com/psmisc/psmisc/-/commit/b6c2b1288bd99f52d962301a2e41a0102d2a2d35 + +This patch has been modified to fit euler os +Signed-off-by: chenmingmin +--- + src/pstree.c | 5 +++-- + 1 files changed, 3 insertions(+), 2 deletions(-) + +diff --git a/src/pstree.c b/src/pstree.c +index 3de0792..b05822e 100644 +--- a/src/pstree.c ++++ b/src/pstree.c +@@ -1030,8 +1030,9 @@ static void read_proc(void) + #ifdef WITH_SELINUX + if (selinux_enabled) + if (getpidcon(pid, &scontext) < 0) { +- perror(path); +- exit(1); ++ (void) fclose(file); ++ free(path); ++ continue; + } + #endif /*WITH_SELINUX */ + if (stat(path, &st) < 0) { +-- +2.22.0.windows.1 + diff --git a/backport-0003-killall-minor-str-length-changes.patch b/backport-0003-killall-minor-str-length-changes.patch new file mode 100644 index 0000000..7f84b1f --- /dev/null +++ b/backport-0003-killall-minor-str-length-changes.patch @@ -0,0 +1,41 @@ +From 8df09a2792712a8852d637d07902896784721228 Mon Sep 17 00:00:00 2001 +From: Craig Small +Date: Mon, 2 Mar 2020 21:56:02 +1100 +Subject: [PATCH 09/20] killall: minor str length changes + +reworked some of the string handling to check for strchr and +strrchr return values. Removed check for unsigned to be negative, +that's not going to happen! + +References: + Coverity 288525 + +https://gitlab.com/psmisc/psmisc/-/commit/8df09a2792712a8852d637d07902896784721228 +--- + src/killall.c | 9 +++++---- + 1 file changed, 5 insertions(+), 4 deletions(-) + +diff --git a/src/killall.c b/src/killall.c +index 557fa51..524760b 100644 +--- a/src/killall.c ++++ b/src/killall.c +@@ -345,11 +345,12 @@ load_process_name_and_age(char *comm, double *process_age_sec, + return -1; + } + fclose(file); +- startcomm = strchr(buf, '(') + 1; +- endcomm = strrchr(startcomm, ')'); ++ if ( NULL == ( startcomm = strchr(buf, '('))) ++ return -1; ++ startcomm++; ++ if ( NULL == ( endcomm = strrchr(startcomm, ')'))) ++ return -1; + lencomm = endcomm - startcomm; +- if (lencomm < 0) +- lencomm = 0; + if (lencomm > COMM_LEN -1) + lencomm = COMM_LEN -1; + strncpy(comm, startcomm, lencomm); +-- +2.22.0.windows.1 + diff --git a/backport-0004-pstree-minor-snprintf-fix.patch b/backport-0004-pstree-minor-snprintf-fix.patch new file mode 100644 index 0000000..370623e --- /dev/null +++ b/backport-0004-pstree-minor-snprintf-fix.patch @@ -0,0 +1,38 @@ +From 8fcc64ab2ca67bc46bdee8d7b50c6c6b9eb09318 Mon Sep 17 00:00:00 2001 +From: Craig Small +Date: Mon, 2 Mar 2020 22:00:25 +1100 +Subject: [PATCH 10/20] pstree: minor snprintf fix + +The referenced commit used size_t as a return value for +snprintf. + +Coverity found the negative check against size_t but the real +problem was using size_t in the first place as an error +returned by snprintf would never be detected. + +References: + commit 5e510d1c9ed8cb61f9c504076a7c4828624b8b07 + Coverity #288526 + +https://gitlab.com/psmisc/psmisc/-/commit/8fcc64ab2ca67bc46bdee8d7b50c6c6b9eb09318 +--- + src/pstree.c | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +diff --git a/src/pstree.c b/src/pstree.c +index c448539..da02564 100644 +--- a/src/pstree.c ++++ b/src/pstree.c +@@ -935,8 +935,7 @@ static char* get_threadname(const pid_t pid, const int tid, const char *comm) + FILE *file; + char *thread_comm, *endcomm, *threadname; + char *path = NULL; +- size_t len = 0; +- int nbytes; ++ int len, nbytes; + char readbuf[BUFSIZ + 1]; + + if (! (threadname = malloc(COMM_LEN + 2 + 1))) { +-- +2.22.0.windows.1 + diff --git a/backport-0005-peekfd-Check-return-value-of-malloc.patch b/backport-0005-peekfd-Check-return-value-of-malloc.patch new file mode 100644 index 0000000..2dd7d03 --- /dev/null +++ b/backport-0005-peekfd-Check-return-value-of-malloc.patch @@ -0,0 +1,32 @@ +From edad7cd77c5b95db2f7fe4e3678e7444a1bcc399 Mon Sep 17 00:00:00 2001 +From: Craig Small +Date: Mon, 2 Mar 2020 22:08:27 +1100 +Subject: [PATCH 11/20] peekfd: Check return value of malloc + +If malloc returned null on lastbuf then we would have had a +derefencing NULL issue. + +References: + Coverity 46258 +https://gitlab.com/psmisc/psmisc/-/commit/edad7cd77c5b95db2f7fe4e3678e7444a1bcc399 +--- + src/peekfd.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/src/peekfd.c b/src/peekfd.c +index f41391a..360b2f7 100644 +--- a/src/peekfd.c ++++ b/src/peekfd.c +@@ -415,7 +415,8 @@ int main(int argc, char **argv) + if (remove_duplicates) { + if (lastbuf) + free(lastbuf); +- lastbuf = malloc(regs.REG_PARAM3); ++ if ( NULL == (lastbuf = malloc(regs.REG_PARAM3))) ++ perror("lastbuf malloc"); + last_buf_size = regs.REG_PARAM3; + } + +-- +2.22.0.windows.1 + diff --git a/backport-0006-fuser-free-local-port-before-return.patch b/backport-0006-fuser-free-local-port-before-return.patch new file mode 100644 index 0000000..a523c83 --- /dev/null +++ b/backport-0006-fuser-free-local-port-before-return.patch @@ -0,0 +1,46 @@ +From 1ab3e9950f4c9cf749802a36e01249dde8e10c3b Mon Sep 17 00:00:00 2001 +From: Craig Small +Date: Mon, 2 Mar 2020 22:16:26 +1100 +Subject: [PATCH 12/20] fuser: free local port before return + +parse_inet allocated a string using strdup() but didn't always +release it. + +References: + Coverity #14401 +https://gitlab.com/psmisc/psmisc/-/commit/1ab3e9950f4c9cf749802a36e01249dde8e10c3b +--- + src/fuser.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/fuser.c b/src/fuser.c +index ac8244a..bbcbed2 100644 +--- a/src/fuser.c ++++ b/src/fuser.c +@@ -605,8 +605,10 @@ int parse_inet(struct names *this_name, struct ip_connections **ip_list) + getaddrinfo(NULL, lcl_port_str, &hints, &res)) != 0) { + fprintf(stderr, _("Cannot resolve local port %s: %s\n"), + lcl_port_str, gai_strerror(errcode)); ++ free(lcl_port_str); + return -1; + } ++ free(lcl_port_str); + if (res == NULL) + return -1; + switch (res->ai_family) { +@@ -624,12 +626,10 @@ int parse_inet(struct names *this_name, struct ip_connections **ip_list) + fprintf(stderr, _("Unknown local port AF %d\n"), + res->ai_family); + freeaddrinfo(res); +- free(lcl_port_str); + return -1; + } + freeaddrinfo(res); + } +- free(lcl_port_str); + res = NULL; + if (rmt_addr_str == NULL && rmt_port_str == NULL) { + add_ip_conn(ip_list, protocol, this_name, ntohs(lcl_port), 0, +-- +2.22.0.windows.1 + diff --git a/backport-0007-peekfd-exit-after-perror.patch b/backport-0007-peekfd-exit-after-perror.patch new file mode 100644 index 0000000..813a792 --- /dev/null +++ b/backport-0007-peekfd-exit-after-perror.patch @@ -0,0 +1,29 @@ +From 02d3bdc1f283645e537b35e1a9cad34e40615277 Mon Sep 17 00:00:00 2001 +From: Craig Small +Date: Mon, 2 Mar 2020 22:27:20 +1100 +Subject: [PATCH 13/20] peekfd: exit() after perror() + +https://gitlab.com/psmisc/psmisc/-/commit/02d3bdc1f283645e537b35e1a9cad34e40615277 +--- + src/peekfd.c | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/src/peekfd.c b/src/peekfd.c +index 360b2f7..36dff04 100644 +--- a/src/peekfd.c ++++ b/src/peekfd.c +@@ -415,8 +415,10 @@ int main(int argc, char **argv) + if (remove_duplicates) { + if (lastbuf) + free(lastbuf); +- if ( NULL == (lastbuf = malloc(regs.REG_PARAM3))) ++ if ( NULL == (lastbuf = malloc(regs.REG_PARAM3))) { + perror("lastbuf malloc"); ++ exit(1); ++ } + last_buf_size = regs.REG_PARAM3; + } + +-- +2.22.0.windows.1 + diff --git a/backport-0008-pstree-consecutive-NULs-in-cmdline-args-wrongly-pars.patch b/backport-0008-pstree-consecutive-NULs-in-cmdline-args-wrongly-pars.patch new file mode 100644 index 0000000..d9c2666 --- /dev/null +++ b/backport-0008-pstree-consecutive-NULs-in-cmdline-args-wrongly-pars.patch @@ -0,0 +1,31 @@ +From c028ba11f90beecbd48d9a9f9ae8151622ea5fbc Mon Sep 17 00:00:00 2001 +From: Jan Rybar +Date: Wed, 29 Apr 2020 17:26:51 +0200 +Subject: [PATCH 16/20] pstree: consecutive NULs in cmdline args wrongly parsed + +https://gitlab.com/psmisc/psmisc/-/commit/c028ba11f90beecbd48d9a9f9ae8151622ea5fbc +--- + src/pstree.c | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/src/pstree.c b/src/pstree.c +index da02564..44e932c 100644 +--- a/src/pstree.c ++++ b/src/pstree.c +@@ -571,8 +571,12 @@ static void set_args(PROC * this, const char *args, int size) + } + this->argc = 0; + for (i = 0; i < size - 1; i++) +- if (!args[i]) ++ if (!args[i]) { + this->argc++; ++ /* now skip consecutive NUL */ ++ while(!args[i] && (i < size -1 )) ++ i++; ++ } + if (!this->argc) + return; + if (!(this->argv = malloc(sizeof(char *) * this->argc))) { +-- +2.22.0.windows.1 + diff --git a/backport-0009-fuser-Less-confused-about-duplicate-dev_id.patch b/backport-0009-fuser-Less-confused-about-duplicate-dev_id.patch new file mode 100644 index 0000000..3c0777b --- /dev/null +++ b/backport-0009-fuser-Less-confused-about-duplicate-dev_id.patch @@ -0,0 +1,107 @@ +From 5c979b38253d187a8ecb8e52a0878b8bb668894f Mon Sep 17 00:00:00 2001 +From: Craig Small +Date: Fri, 22 May 2020 16:21:10 +1000 +Subject: [PATCH 17/20] fuser: Less confused about duplicate dev_id + +NFS mounts from the same server have the same device ID. This means +using the -m option a process using one of those mounts will be +"found" in all of the others too. + +lsof doesn't have this confusion as it checks the real path against +the mount point and only matches if they start the same. + +I think it would be confused with double stacked NFS shares such +as /nfs/SHARE1/blah/SHARE2 with the open file in SHARE2 but +there are limits. + +References: + psmisc/psmisc#10 + +https://gitlab.com/psmisc/psmisc/-/commit/5c979b38253d187a8ecb8e52a0878b8bb668894f +This patch has been modified to fit euler os +Signed-off-by: chenmingmin +--- + src/fuser.c | 22 ++++++++++++++++++++-- + src/fuser.h | 2 +- + 3 files changed, 21 insertions(+), 3 deletions(-) +diff --git a/src/fuser.c b/src/fuser.c +index bbcbed2..70da121 100644 +--- a/src/fuser.c ++++ b/src/fuser.c +@@ -56,6 +56,10 @@ + #define MAXSYMLINKS SYMLINK_MAX + #endif + ++#ifdef ENABLE_NLS ++#include ++#endif ++ + #include "fuser.h" + #include "signals.h" + #include "i18n.h" +@@ -64,6 +68,10 @@ + + //#define DEBUG 1 + ++#ifndef PATH_MAX ++#define PATH_MAX 4096 ++#endif /* PATH_MAX */ ++ + #define NAME_FIELD 20 /* space reserved for file name */ + /* Function defines */ + static void add_matched_proc(struct names *name_list, const pid_t pid, +@@ -1531,12 +1539,12 @@ print_matches(struct names *names_head, const opt_type opts, + + static struct stat *get_pidstat(const pid_t pid, const char *filename) + { +- char pathname[256]; ++ char pathname[PATH_MAX]; + struct stat *st; + + if ((st = (struct stat *)malloc(sizeof(struct stat))) == NULL) + return NULL; +- snprintf(pathname, 256, "/proc/%d/%s", pid, filename); ++ snprintf(pathname, PATH_MAX-1, "/proc/%d/%s", pid, filename); + if (timeout(thestat, pathname, st, 5) != 0) { + free(st); + return NULL; +@@ -1558,6 +1566,7 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head, + struct stat st, lst; + char *dirpath; + char filepath[PATH_MAX]; ++ char real_filepath[PATH_MAX]; + + if (asprintf(&dirpath, "/proc/%d/%s", pid, dirname) < 0) + return; +@@ -1596,6 +1605,15 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head, + dev_tmp = dev_tmp->next) { + if (thedev != dev_tmp->device) + continue; ++ ++ /* check the paths match */ ++ if (readlink(filepath, real_filepath, PATH_MAX-1) < 0) { ++ if (strncmp(dev_tmp->name->filename, filepath, strlen(dev_tmp->name->filename)) != 0) ++ continue; ++ } else { ++ if (strncmp(dev_tmp->name->filename, real_filepath, strlen(dev_tmp->name->filename)) != 0) ++ continue; ++ } + if (access == ACCESS_FILE + && (lstat(filepath, &lst) == 0) + && (lst.st_mode & S_IWUSR)) { +diff --git a/src/fuser.h b/src/fuser.h +index 93020d5..4500ec5 100644 +--- a/src/fuser.h ++++ b/src/fuser.h +@@ -40,7 +40,7 @@ struct procs { + struct names { + char *filename; + unsigned char name_space; +- struct stat st; ++ struct stat st; + struct procs *matched_procs; + struct names *next; + }; +-- +2.22.0.windows.1 + diff --git a/backport-0010-fuser-Check-pathname-only-on-non-block-devices.patch b/backport-0010-fuser-Check-pathname-only-on-non-block-devices.patch new file mode 100644 index 0000000..e8bbbba --- /dev/null +++ b/backport-0010-fuser-Check-pathname-only-on-non-block-devices.patch @@ -0,0 +1,56 @@ +From b4566f854f29cad3d2249abcb7e472f5d3fbf169 Mon Sep 17 00:00:00 2001 +From: Craig Small +Date: Tue, 27 Oct 2020 21:59:25 +1100 +Subject: [PATCH] fuser: Check pathname only on non-block devices + +The referenced commit we would check the pathname to +ensure it matched our target. This worked fine for +real files. However for block devices it would fail +because "/dev/sda1" doesn't match "/mnt/myfile". + +We only check the pathname if the thing we are matching +against is not a block file. + +Thanks to @MarsChan for the report and also the suggested +fix! + +References: + commit 5c979b38253d187a8ecb8e52a0878b8bb668894f + psmisc/psmisc#31 + +Signed-off-by: Craig Small +--- + ChangeLog | 1 + + src/fuser.c | 16 +++++++++------- + 1 files changed, 9 insertions(+), 7 deletions(-) + +diff --git a/src/fuser.c b/src/fuser.c +index 70da121..03e6237 100644 +--- a/src/fuser.c ++++ b/src/fuser.c +@@ -1606,13 +1606,15 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head, + if (thedev != dev_tmp->device) + continue; + +- /* check the paths match */ +- if (readlink(filepath, real_filepath, PATH_MAX-1) < 0) { +- if (strncmp(dev_tmp->name->filename, filepath, strlen(dev_tmp->name->filename)) != 0) +- continue; +- } else { +- if (strncmp(dev_tmp->name->filename, real_filepath, strlen(dev_tmp->name->filename)) != 0) +- continue; ++ /* check the paths match if it is not a block device */ ++ if (! S_ISBLK(dev_tmp->name->st.st_mode)) { ++ if (readlink(filepath, real_filepath, PATH_MAX-1) < 0) { ++ if (strncmp(dev_tmp->name->filename, filepath, strlen(dev_tmp->name->filename)) != 0) ++ continue; ++ } else { ++ if (strncmp(dev_tmp->name->filename, real_filepath, strlen(dev_tmp->name->filename)) != 0) ++ continue; ++ } + } + if (access == ACCESS_FILE + && (lstat(filepath, &lst) == 0) +-- +1.8.3.1 + diff --git a/psmisc.spec b/psmisc.spec index c58e303..0a6d107 100644 --- a/psmisc.spec +++ b/psmisc.spec @@ -1,12 +1,23 @@ Name: psmisc Version: 23.3 -Release: 1 +Release: 2 Summary: Utilities for managing processes on your system License: GPLv2+ URL: https://gitlab.com/psmisc/psmisc Source0: https://sourceforge.net/projects/%{name}/files/%{name}/%{name}-%{version}.tar.xz BuildRequires: libselinux-devel gettext ncurses-devel autoconf automake gcc git +Patch0000: backport-0001-pstree-do-not-crash-on-missing-proc-xxxx-directory.patch +Patch0001: backport-0002-pstree-additional-for-do-not-crash-on-missing-proces.patch +Patch0002: backport-0003-killall-minor-str-length-changes.patch +Patch0003: backport-0004-pstree-minor-snprintf-fix.patch +Patch0004: backport-0005-peekfd-Check-return-value-of-malloc.patch +Patch0005: backport-0006-fuser-free-local-port-before-return.patch +Patch0006: backport-0007-peekfd-exit-after-perror.patch +Patch0007: backport-0008-pstree-consecutive-NULs-in-cmdline-args-wrongly-pars.patch +Patch0008: backport-0009-fuser-Less-confused-about-duplicate-dev_id.patch +Patch0009: backport-0010-fuser-Check-pathname-only-on-non-block-devices.patch + Patch9001: bugfix-fix-pstree-coredump-due-pid-reuse.patch %description @@ -35,6 +46,9 @@ mv $RPM_BUILD_ROOT%{_bindir}/fuser $RPM_BUILD_ROOT%{_sbindir} %doc AUTHORS ChangeLog README %changelog +* Thu Nov 03 2020 xinghe - 23.3-2 +- sync patchs + * Thu Jul 16 2020 jinzhimin - 23.3-1 - Type:enhancement - ID:NA