]> granicus.if.org Git - procps-ng/commitdiff
library: correct the procps_pid_length() +1 distortion
authorJim Warner <james.warner@comcast.net>
Sun, 17 Apr 2016 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@enc.com.au>
Mon, 18 Apr 2016 09:29:41 +0000 (19:29 +1000)
Unfortunately, reading that '/proc/sys/kernel/pid_max'
file returns a newline, which we will now account for.

[ also, we should use the existing dedicated buffer ]

Reference(s):
. original 'procps_pid_length' introduction
commit ccb6ae8de14b0cde25b84369ef995bcd69cbf7b6

Signed-off-by: Jim Warner <james.warner@comcast.net>
proc/sysinfo.c

index 0cd8759f758b7fe4aab4c3732ce1e5fbe06c2ebc..2189433b9355bbd8b4019dca2973abd88916e89d 100644 (file)
@@ -197,8 +197,10 @@ PROCPS_EXPORT unsigned int procps_pid_length(void)
 
     pid_length = DEFAULT_PID_LENGTH;
     if ((fp = fopen(PROCFS_PID_MAX, "r")) != NULL) {
-        if (fgets(buf, 24, fp) != NULL) {
-            pid_length = strlen(buf);
+        if (fgets(pidbuf, sizeof(pidbuf), fp) != NULL) {
+            pid_length = strlen(pidbuf);
+            if (pidbuf[pid_length-1] == '\n')
+                --pid_length;
         }
         fclose(fp);
     }