Tue Oct 6 00:19:05 2020 UTC ()
psmisc: fix sscanf usage bug under musl libc

C99 says that the %15c conversion specifier matches *exactly* 15
characters, so if the process name is shorter than 15 characters,
it is not matched and 0 is returned. Some implementations (such as
glibc) return a match, even with fewer characters than the field
width, but this cannot be assumed.

Instead, use %15[^)], as in upstream commit [0], which matches a
non-empty sequence of characters other than ')'.

[0] https://gitlab.com/psmisc/psmisc/-/commit/ca2b176889729a7347bd95b832b9a5bb39fec229


(mcf)
diff -r1.32 -r1.33 pkgsrc/sysutils/psmisc/Makefile
diff -r1.8 -r1.9 pkgsrc/sysutils/psmisc/distinfo
diff -r1.6 -r1.7 pkgsrc/sysutils/psmisc/patches/patch-af

cvs diff -r1.32 -r1.33 pkgsrc/sysutils/psmisc/Makefile (expand / switch to unified diff)

--- pkgsrc/sysutils/psmisc/Makefile 2020/03/20 11:58:22 1.32
+++ pkgsrc/sysutils/psmisc/Makefile 2020/10/06 00:19:05 1.33
@@ -1,18 +1,18 @@ @@ -1,18 +1,18 @@
1# $NetBSD: Makefile,v 1.32 2020/03/20 11:58:22 nia Exp $ 1# $NetBSD: Makefile,v 1.33 2020/10/06 00:19:05 mcf Exp $
2 2
3DISTNAME= psmisc-20.1 3DISTNAME= psmisc-20.1
4CATEGORIES= sysutils 4CATEGORIES= sysutils
5PKGREVISION= 3 5PKGREVISION= 4
6MASTER_SITES= ${MASTER_SITE_SOURCEFORGE:=psmisc/} 6MASTER_SITES= ${MASTER_SITE_SOURCEFORGE:=psmisc/}
7 7
8MAINTAINER= pkgsrc-users@NetBSD.org 8MAINTAINER= pkgsrc-users@NetBSD.org
9HOMEPAGE= http://psmisc.sourceforge.net/ 9HOMEPAGE= http://psmisc.sourceforge.net/
10COMMENT= Miscellaneous procfs tools: killall, pidof, and pstree 10COMMENT= Miscellaneous procfs tools: killall, pidof, and pstree
11LICENSE= gnu-gpl-v2 11LICENSE= gnu-gpl-v2
12 12
13CONFLICTS+= pstree<=2.16 13CONFLICTS+= pstree<=2.16
14 14
15GNU_CONFIGURE= yes 15GNU_CONFIGURE= yes
16PLIST_VARS+= fuser 16PLIST_VARS+= fuser
17LIBS+= ${BUILDLINK_LDADD.getopt} 17LIBS+= ${BUILDLINK_LDADD.getopt}
18 18

cvs diff -r1.8 -r1.9 pkgsrc/sysutils/psmisc/distinfo (expand / switch to unified diff)

--- pkgsrc/sysutils/psmisc/distinfo 2015/11/04 01:32:26 1.8
+++ pkgsrc/sysutils/psmisc/distinfo 2020/10/06 00:19:05 1.9
@@ -1,12 +1,12 @@ @@ -1,12 +1,12 @@
1$NetBSD: distinfo,v 1.8 2015/11/04 01:32:26 agc Exp $ 1$NetBSD: distinfo,v 1.9 2020/10/06 00:19:05 mcf Exp $
2 2
3SHA1 (psmisc-20.1.tar.gz) = e969a2f539b181c372b0f82bbbd430c4d57d5d6b 3SHA1 (psmisc-20.1.tar.gz) = e969a2f539b181c372b0f82bbbd430c4d57d5d6b
4RMD160 (psmisc-20.1.tar.gz) = 48698ad9f431c881bcb42394f5c912ef91b84d2b 4RMD160 (psmisc-20.1.tar.gz) = 48698ad9f431c881bcb42394f5c912ef91b84d2b
5SHA512 (psmisc-20.1.tar.gz) = 14553afd185d968042a10eefadaec089f4deb821fee70b69d520565ccbaa485c65137af2279bcfc2abbfdeb3e35bad2beaa5357372fbe6cfa587d10e9bdc2f9b 5SHA512 (psmisc-20.1.tar.gz) = 14553afd185d968042a10eefadaec089f4deb821fee70b69d520565ccbaa485c65137af2279bcfc2abbfdeb3e35bad2beaa5357372fbe6cfa587d10e9bdc2f9b
6Size (psmisc-20.1.tar.gz) = 57767 bytes 6Size (psmisc-20.1.tar.gz) = 57767 bytes
7SHA1 (patch-ab) = 74134f6cd2ea0270fdbaff8c0acb9e40767cc5cb 7SHA1 (patch-ab) = 74134f6cd2ea0270fdbaff8c0acb9e40767cc5cb
8SHA1 (patch-ac) = 9f9a7c7c5155345a1045aee70a2dd65a25ec7219 8SHA1 (patch-ac) = 9f9a7c7c5155345a1045aee70a2dd65a25ec7219
9SHA1 (patch-ad) = 6e2886ca59160d161d334e276675f187f138db7c 9SHA1 (patch-ad) = 6e2886ca59160d161d334e276675f187f138db7c
10SHA1 (patch-ae) = 484305118582c575f8c4827783aa3d5f57b25b5d 10SHA1 (patch-ae) = 484305118582c575f8c4827783aa3d5f57b25b5d
11SHA1 (patch-af) = c89f887f572cb7bf22ff05fc6b76eca7fcb34337 11SHA1 (patch-af) = ecba31c5e44291e695eb4b9ea19b9a70cdbd3f67
12SHA1 (patch-ag) = a03a4a0c0dbf065e2b2785cee8f23579a11ae13f 12SHA1 (patch-ag) = a03a4a0c0dbf065e2b2785cee8f23579a11ae13f

cvs diff -r1.6 -r1.7 pkgsrc/sysutils/psmisc/patches/patch-af (expand / switch to unified diff)

--- pkgsrc/sysutils/psmisc/patches/patch-af 2014/09/23 22:18:21 1.6
+++ pkgsrc/sysutils/psmisc/patches/patch-af 2020/10/06 00:19:05 1.7
@@ -1,17 +1,20 @@ @@ -1,17 +1,20 @@
1$NetBSD: patch-af,v 1.6 2014/09/23 22:18:21 jperkin Exp $ 1$NetBSD: patch-af,v 1.7 2020/10/06 00:19:05 mcf Exp $
2 2
3Need limits.h for PATH_MAX 3Need limits.h for PATH_MAX
4 4
 5Fix sscanf usage bug on musl libc and uclibc (upstream commit
 6https://gitlab.com/psmisc/psmisc/-/commit/ca2b176889729a7347bd95b832b9a5bb39fec229)
 7
5--- src/pstree.c.orig 2000-12-18 05:59:23.000000000 +0000 8--- src/pstree.c.orig 2000-12-18 05:59:23.000000000 +0000
6+++ src/pstree.c 9+++ src/pstree.c
7@@ -15,19 +15,22 @@ 10@@ -15,19 +15,22 @@
8 #include <getopt.h> 11 #include <getopt.h>
9 #include <pwd.h> 12 #include <pwd.h>
10 #include <dirent.h> 13 #include <dirent.h>
11+#include <limits.h> 14+#include <limits.h>
12 #include <termios.h> 15 #include <termios.h>
13+#ifdef HAVE_TERMCAP_H 16+#ifdef HAVE_TERMCAP_H
14 #include <termcap.h> 17 #include <termcap.h>
15+#endif 18+#endif
16 #include <sys/types.h> 19 #include <sys/types.h>
17 #include <sys/stat.h> 20 #include <sys/stat.h>
@@ -55,50 +58,61 @@ Need limits.h for PATH_MAX @@ -55,50 +58,61 @@ Need limits.h for PATH_MAX
55+ if (current->highlight && (tmp = tgetstr ("me", &pbuf))) 58+ if (current->highlight && (tmp = tgetstr ("me", &pbuf)))
56 tputs (tmp, 1, putchar); 59 tputs (tmp, 1, putchar);
57 if (print_args) 60 if (print_args)
58 { 61 {
59@@ -504,7 +510,7 @@ read_proc (void) 62@@ -504,7 +510,7 @@ read_proc (void)
60 while ((de = readdir (dir)) != NULL) 63 while ((de = readdir (dir)) != NULL)
61 if ((pid = atoi (de->d_name)) != 0) 64 if ((pid = atoi (de->d_name)) != 0)
62 { 65 {
63- sprintf (path, "%s/%d/stat", PROC_BASE, pid); 66- sprintf (path, "%s/%d/stat", PROC_BASE, pid);
64+ sprintf (path, "%s/%d/%s", PROC_BASE, pid, STATUS_FILE); 67+ sprintf (path, "%s/%d/%s", PROC_BASE, pid, STATUS_FILE);
65 if ((file = fopen (path, "r")) != NULL) 68 if ((file = fopen (path, "r")) != NULL)
66 { 69 {
67 empty = 0; 70 empty = 0;
68@@ -513,6 +519,10 @@ read_proc (void) 71@@ -513,16 +519,19 @@ read_proc (void)
69 perror (path); 72 perror (path);
70 exit (1); 73 exit (1);
71 } 74 }
72+#ifdef BSD_44_PROCFS 75+#ifdef BSD_44_PROCFS
73+ if (fscanf(file, "%s %*d %d", comm, &ppid) == 2) 76+ if (fscanf(file, "%s %*d %d", comm, &ppid) == 2)
74+ { { { 77+ { { {
75+#else 78+#else
76 fread(readbuf, BUFSIZ, 1, file) ; 79 fread(readbuf, BUFSIZ, 1, file) ;
77 if (ferror(file) == 0)  80 if (ferror(file) == 0)
78 { 81 {
79@@ -532,11 +542,12 @@ read_proc (void) 82 memset(comm, '\0', COMM_LEN+1);
 83 tmpptr = strrchr(readbuf, ')'); /* find last ) */
 84- *tmpptr = '\0';
 85 /* We now have readbuf with pid and cmd, and tmpptr+2
 86 * with the rest */
 87 /*printf("readbuf: %s\n", readbuf);*/
 88- if (sscanf(readbuf, "%*d (%15c", comm) == 1)
 89+ if (sscanf(readbuf, "%*d (%15[^)]", comm) == 1)
 90 {
 91 /*printf("tmpptr: %s\n", tmpptr+2);*/
 92 if (sscanf(tmpptr+2, "%*c %d", &ppid) == 1)
 93@@ -532,11 +541,12 @@ read_proc (void)
80 (file, "%d (%s) %c %d", &dummy, comm, (char *) &dummy, 94 (file, "%d (%s) %c %d", &dummy, comm, (char *) &dummy,
81 &ppid) == 4) 95 &ppid) == 4)
82 */ 96 */
83+#endif 97+#endif
84 if (!print_args) 98 if (!print_args)
85 add_proc (comm, pid, ppid, st.st_uid, NULL, 0); 99 add_proc (comm, pid, ppid, st.st_uid, NULL, 0);
86 else 100 else
87 { 101 {
88- sprintf (path, "%s/%d/cmdline", PROC_BASE, pid); 102- sprintf (path, "%s/%d/cmdline", PROC_BASE, pid);
89+ sprintf (path, "%s/%d/%s", PROC_BASE, pid, CMDLINE_FILE); 103+ sprintf (path, "%s/%d/%s", PROC_BASE, pid, CMDLINE_FILE);
90 if ((fd = open (path, O_RDONLY)) < 0) 104 if ((fd = open (path, O_RDONLY)) < 0)
91 { 105 {
92 perror (path); 106 perror (path);
93@@ -641,7 +652,11 @@ main (int argc, char **argv) 107@@ -641,7 +651,11 @@ main (int argc, char **argv)
94 switch (c) 108 switch (c)
95 { 109 {
96 case 'a': 110 case 'a':
97+#if defined(BSD_44_PROCFS) && !defined(BSD_PROCFS_CMDLINE) 111+#if defined(BSD_44_PROCFS) && !defined(BSD_PROCFS_CMDLINE)
98+ print_args = 0; 112+ print_args = 0;
99+#else 113+#else
100 print_args = 1; 114 print_args = 1;
101+#endif 115+#endif
102 break; 116 break;
103 case 'c': 117 case 'c':
104 compact = 0; 118 compact = 0;