!6 sync patchs

From: @xinghe_1
Reviewed-by: @SuperSix173
Signed-off-by: @SuperSix173
This commit is contained in:
openeuler-ci-bot 2020-11-03 18:30:51 +08:00 committed by Gitee
commit f7db24be8f
11 changed files with 460 additions and 1 deletions

View File

@ -0,0 +1,32 @@
From d21bee476432e0d0442662fa7899d4dd4897e097 Mon Sep 17 00:00:00 2001
From: Piotr Praszmo <piotr.praszmo@nokia.com>
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

View File

@ -0,0 +1,33 @@
From b6c2b1288bd99f52d962301a2e41a0102d2a2d35 Mon Sep 17 00:00:00 2001
From: Craig Small <csmall@dropbear.xyz>
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 <chenmingmin@huawei.com>
---
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

View File

@ -0,0 +1,41 @@
From 8df09a2792712a8852d637d07902896784721228 Mon Sep 17 00:00:00 2001
From: Craig Small <csmall@dropbear.xyz>
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

View File

@ -0,0 +1,38 @@
From 8fcc64ab2ca67bc46bdee8d7b50c6c6b9eb09318 Mon Sep 17 00:00:00 2001
From: Craig Small <csmall@dropbear.xyz>
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

View File

@ -0,0 +1,32 @@
From edad7cd77c5b95db2f7fe4e3678e7444a1bcc399 Mon Sep 17 00:00:00 2001
From: Craig Small <csmall@dropbear.xyz>
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

View File

@ -0,0 +1,46 @@
From 1ab3e9950f4c9cf749802a36e01249dde8e10c3b Mon Sep 17 00:00:00 2001
From: Craig Small <csmall@dropbear.xyz>
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

View File

@ -0,0 +1,29 @@
From 02d3bdc1f283645e537b35e1a9cad34e40615277 Mon Sep 17 00:00:00 2001
From: Craig Small <csmall@dropbear.xyz>
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

View File

@ -0,0 +1,31 @@
From c028ba11f90beecbd48d9a9f9ae8151622ea5fbc Mon Sep 17 00:00:00 2001
From: Jan Rybar <jrybar@redhat.com>
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

View File

@ -0,0 +1,107 @@
From 5c979b38253d187a8ecb8e52a0878b8bb668894f Mon Sep 17 00:00:00 2001
From: Craig Small <csmall@dropbear.xyz>
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 <chenmingmin@huawei.com>
---
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 <locale.h>
+#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

View File

@ -0,0 +1,56 @@
From b4566f854f29cad3d2249abcb7e472f5d3fbf169 Mon Sep 17 00:00:00 2001
From: Craig Small <csmall@dropbear.xyz>
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 <csmall@dropbear.xyz>
---
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

View File

@ -1,12 +1,23 @@
Name: psmisc Name: psmisc
Version: 23.3 Version: 23.3
Release: 1 Release: 2
Summary: Utilities for managing processes on your system Summary: Utilities for managing processes on your system
License: GPLv2+ License: GPLv2+
URL: https://gitlab.com/psmisc/psmisc URL: https://gitlab.com/psmisc/psmisc
Source0: https://sourceforge.net/projects/%{name}/files/%{name}/%{name}-%{version}.tar.xz Source0: https://sourceforge.net/projects/%{name}/files/%{name}/%{name}-%{version}.tar.xz
BuildRequires: libselinux-devel gettext ncurses-devel autoconf automake gcc git 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 Patch9001: bugfix-fix-pstree-coredump-due-pid-reuse.patch
%description %description
@ -35,6 +46,9 @@ mv $RPM_BUILD_ROOT%{_bindir}/fuser $RPM_BUILD_ROOT%{_sbindir}
%doc AUTHORS ChangeLog README %doc AUTHORS ChangeLog README
%changelog %changelog
* Thu Nov 03 2020 xinghe <xinghe1@huawei.com> - 23.3-2
- sync patchs
* Thu Jul 16 2020 jinzhimin <jinzhimin2@huawei.com> - 23.3-1 * Thu Jul 16 2020 jinzhimin <jinzhimin2@huawei.com> - 23.3-1
- Type:enhancement - Type:enhancement
- ID:NA - ID:NA