]> granicus.if.org Git - procps-ng/commitdiff
proc/sysinfo.c: Fix off-by-one in get_pid_digits().
authorQualys Security Advisory <qsa@qualys.com>
Thu, 1 Jan 1970 00:00:00 +0000 (00:00 +0000)
committerCraig Small <csmall@enc.com.au>
Fri, 18 May 2018 21:32:21 +0000 (07:32 +1000)
At "pidbuf[rc] = '\0';" if "rc = read()" returns "sizeof pidbuf"
(unlikely to ever happen, but still).

proc/sysinfo.c

index f0f705ffe62aab623b4cf306bc320fe701eee69d..42646942bdeae18719e64e1f218f50feae74f7f4 100644 (file)
@@ -1140,7 +1140,7 @@ unsigned get_pid_digits(void){
   ret = 5;
   fd = open("/proc/sys/kernel/pid_max", O_RDONLY);
   if(fd==-1) goto out;
-  rc = read(fd, pidbuf, sizeof pidbuf);
+  rc = read(fd, pidbuf, sizeof pidbuf - 1);
   close(fd);
   if(rc<3) goto out;
   pidbuf[rc] = '\0';