]> granicus.if.org Git - procps-ng/commitdiff
library: fix a potential error relating to 'exe' logic
authorJim Warner <james.warner@comcast.net>
Tue, 22 Dec 2020 06:00:00 +0000 (00:00 -0600)
committerCraig Small <csmall@dropbear.xyz>
Mon, 28 Dec 2020 21:48:23 +0000 (08:48 +1100)
After 'errno' management was standardized, a couple of
fields were added to the <pids> api. Only 1 (PIDS_EXE)
involved dynamic memory and, unfortunately, it did not
conform to that expected normalized ENOMEM convention.

Reference(s):
. Jun 2018, added 'exe' to library
commit ad4269f1189d5a7d68765e291bcfa981b6731c25
. Nov 2017, standardized 'errno' management
commit 06be33b43e5ff3f2658e77ef79441ac2e970cfd7

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

index 5d6483370deca3c482fab6131b453e233c87081d..3259131668a8f9d9d84db99ef6fc9f8d54e368ce 100644 (file)
@@ -1118,8 +1118,10 @@ static proc_t* simple_readproc(PROCTAB *restrict const PT, proc_t *restrict cons
     if (flags & PROC_FILL_LUID)                 // value the login user id
         p->luid = login_uid(path);
 
-    if (flags & PROC_FILL_EXE)
-        p->exe = readlink_exe(path);
+    if (flags & PROC_FILL_EXE) {
+        if (!(p->exe = readlink_exe(path)))
+            rc += 1;
+    }
 
     if (rc == 0) return p;
     errno = ENOMEM;
@@ -1211,8 +1213,10 @@ static proc_t* simple_readtask(PROCTAB *restrict const PT, proc_t *restrict cons
     if (flags & PROC_FILLSYSTEMD)                   // get sd-login.h stuff
         rc += sd2proc(t);
 
-    if (flags & PROC_FILL_EXE)
-        t->exe = readlink_exe(path);
+    if (flags & PROC_FILL_EXE) {
+        if (!(t->exe = readlink_exe(path)))
+            rc += 1;
+    }
 #ifdef FALSE_THREADS
     }
 #endif