pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/sysutils/psmisc psmisc: fix sscanf usage bug under mus...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/bc20d1c6a270
branches:  trunk
changeset: 440305:bc20d1c6a270
user:      mcf <mcf%pkgsrc.org@localhost>
date:      Tue Oct 06 00:19:05 2020 +0000

description:
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

diffstat:

 sysutils/psmisc/Makefile         |   4 ++--
 sysutils/psmisc/distinfo         |   4 ++--
 sysutils/psmisc/patches/patch-af |  22 ++++++++++++++++++----
 3 files changed, 22 insertions(+), 8 deletions(-)

diffs (83 lines):

diff -r f9b0262774f7 -r bc20d1c6a270 sysutils/psmisc/Makefile
--- a/sysutils/psmisc/Makefile  Tue Oct 06 00:11:47 2020 +0000
+++ b/sysutils/psmisc/Makefile  Tue Oct 06 00:19:05 2020 +0000
@@ -1,8 +1,8 @@
-# $NetBSD: Makefile,v 1.32 2020/03/20 11:58:22 nia Exp $
+# $NetBSD: Makefile,v 1.33 2020/10/06 00:19:05 mcf Exp $
 
 DISTNAME=              psmisc-20.1
 CATEGORIES=            sysutils
-PKGREVISION=           3
+PKGREVISION=           4
 MASTER_SITES=          ${MASTER_SITE_SOURCEFORGE:=psmisc/}
 
 MAINTAINER=            pkgsrc-users%NetBSD.org@localhost
diff -r f9b0262774f7 -r bc20d1c6a270 sysutils/psmisc/distinfo
--- a/sysutils/psmisc/distinfo  Tue Oct 06 00:11:47 2020 +0000
+++ b/sysutils/psmisc/distinfo  Tue Oct 06 00:19:05 2020 +0000
@@ -1,4 +1,4 @@
-$NetBSD: distinfo,v 1.8 2015/11/04 01:32:26 agc Exp $
+$NetBSD: distinfo,v 1.9 2020/10/06 00:19:05 mcf Exp $
 
 SHA1 (psmisc-20.1.tar.gz) = e969a2f539b181c372b0f82bbbd430c4d57d5d6b
 RMD160 (psmisc-20.1.tar.gz) = 48698ad9f431c881bcb42394f5c912ef91b84d2b
@@ -8,5 +8,5 @@
 SHA1 (patch-ac) = 9f9a7c7c5155345a1045aee70a2dd65a25ec7219
 SHA1 (patch-ad) = 6e2886ca59160d161d334e276675f187f138db7c
 SHA1 (patch-ae) = 484305118582c575f8c4827783aa3d5f57b25b5d
-SHA1 (patch-af) = c89f887f572cb7bf22ff05fc6b76eca7fcb34337
+SHA1 (patch-af) = ecba31c5e44291e695eb4b9ea19b9a70cdbd3f67
 SHA1 (patch-ag) = a03a4a0c0dbf065e2b2785cee8f23579a11ae13f
diff -r f9b0262774f7 -r bc20d1c6a270 sysutils/psmisc/patches/patch-af
--- a/sysutils/psmisc/patches/patch-af  Tue Oct 06 00:11:47 2020 +0000
+++ b/sysutils/psmisc/patches/patch-af  Tue Oct 06 00:19:05 2020 +0000
@@ -1,7 +1,10 @@
-$NetBSD: patch-af,v 1.6 2014/09/23 22:18:21 jperkin Exp $
+$NetBSD: patch-af,v 1.7 2020/10/06 00:19:05 mcf Exp $
 
 Need limits.h for PATH_MAX
 
+Fix sscanf usage bug on musl libc and uclibc (upstream commit
+https://gitlab.com/psmisc/psmisc/-/commit/ca2b176889729a7347bd95b832b9a5bb39fec229)
+
 --- src/pstree.c.orig  2000-12-18 05:59:23.000000000 +0000
 +++ src/pstree.c
 @@ -15,19 +15,22 @@
@@ -65,7 +68,7 @@
        if ((file = fopen (path, "r")) != NULL)
          {
            empty = 0;
-@@ -513,6 +519,10 @@ read_proc (void)
+@@ -513,16 +519,19 @@ read_proc (void)
                perror (path);
                exit (1);
              }
@@ -76,7 +79,18 @@
              fread(readbuf, BUFSIZ, 1, file) ;
              if (ferror(file) == 0) 
              {
-@@ -532,11 +542,12 @@ read_proc (void)
+               memset(comm, '\0', COMM_LEN+1);
+               tmpptr = strrchr(readbuf, ')'); /* find last ) */
+-              *tmpptr = '\0';
+               /* We now have readbuf with pid and cmd, and tmpptr+2
+                * with the rest */
+               /*printf("readbuf: %s\n", readbuf);*/
+-              if (sscanf(readbuf, "%*d (%15c", comm) == 1)
++              if (sscanf(readbuf, "%*d (%15[^)]", comm) == 1)
+               {
+                 /*printf("tmpptr: %s\n", tmpptr+2);*/
+                 if (sscanf(tmpptr+2, "%*c %d", &ppid) == 1)
+@@ -532,11 +541,12 @@ read_proc (void)
                (file, "%d (%s) %c %d", &dummy, comm, (char *) &dummy,
                 &ppid) == 4)
              */
@@ -90,7 +104,7 @@
                    if ((fd = open (path, O_RDONLY)) < 0)
                      {
                        perror (path);
-@@ -641,7 +652,11 @@ main (int argc, char **argv)
+@@ -641,7 +651,11 @@ main (int argc, char **argv)
      switch (c)
        {
        case 'a':



Home | Main Index | Thread Index | Old Index