procps/proc
Craig Small 39d4d147d7 library: Better PID file checks
This started off with fixing the compilier warning:

proc/readproc.c: In function ‘simple_nextpid’:
proc/readproc.c:1373:38: warning: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size 58 [-Wformat-truncation=]
 1373 |   snprintf(path, PROCPATHLEN, "/proc/%s", ent->d_name);
      |                                      ^~
proc/readproc.c:1373:3: note: ‘snprintf’ output between 7 and 262 bytes into a destination of size 64
 1373 |   snprintf(path, PROCPATHLEN, "/proc/%s", ent->d_name);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

We know that ent->d_name will fit under 64 bytes because we check the
name starts with a digit. The first change was simple and changed the
printf to use tgid like the task function below it.

Is everything under /proc that starts with a digit a directory with a
PID only? Today, it is but there are no guarantees.

The entire function works ok if every non-pid directory doesn't start
with a number. We don't check for strtoul() having an issue nor
if the for loop just falls off the end. The moment the kernel guys
(or some module writer) think "/proc/12mykernelval" is a neat idea this
function is in trouble. We won't get buffer overflow as we are
using snprintf at least.

This change now:
 We check if strtoul() actually came across a number
 Process the pid directory as a conditional branch
 Treat falling off the for loop as a not-found

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2022-01-08 07:49:13 +11:00
..
.gitignore build-sys: added a 'test_Itemtables' to testing scheme 2020-08-17 21:49:14 +10:00
COPYING miscellaneous: clean up trailing whitespace once again 2013-04-07 18:05:01 +10:00
devname.c library: extend thread safety to more static variables 2021-10-25 21:51:18 +11:00
devname.h library: eliminate inappropriate '__BEGIN_DECLS' macro 2018-05-06 07:19:38 +10:00
diskstats.c misc: amend the man page & source file copyright dates 2022-01-07 19:19:15 +11:00
diskstats.h misc: amend the man page & source file copyright dates 2022-01-07 19:19:15 +11:00
escape.c library: eliminate those warnings for '-Wpointer-sign' 2022-01-07 19:19:15 +11:00
escape.h library: eliminate those warnings for '-Wpointer-sign' 2022-01-07 19:19:15 +11:00
libproc-2.pc.in library: Rename to libproc-2 2021-02-20 22:30:31 +11:00
libproc-2.sym library: Rename to libproc-2 2021-02-20 22:30:31 +11:00
meminfo.c misc: amend the man page & source file copyright dates 2022-01-07 19:19:15 +11:00
meminfo.h misc: amend the man page & source file copyright dates 2022-01-07 19:19:15 +11:00
misc.h misc: amend the man page & source file copyright dates 2022-01-07 19:19:15 +11:00
namespace.c all: make buildable again for new 'misc.h' header file 2021-01-21 17:30:25 +11:00
numa.c misc: amend the man page & source file copyright dates 2022-01-07 19:19:15 +11:00
numa.h misc: amend the man page & source file copyright dates 2022-01-07 19:19:15 +11:00
pids.c misc: amend the man page & source file copyright dates 2022-01-07 19:19:15 +11:00
pids.h misc: amend the man page & source file copyright dates 2022-01-07 19:19:15 +11:00
procps-private.h library: eliminate unused 'FUNCTION' in private header 2020-09-13 10:00:49 +10:00
pwcache.c library: extend thread safety to more static variables 2021-10-25 21:51:18 +11:00
pwcache.h library: eliminate inappropriate '__BEGIN_DECLS' macro 2018-05-06 07:19:38 +10:00
readproc.c library: Better PID file checks 2022-01-08 07:49:13 +11:00
readproc.h library: add support for the 'LIBPROC_HIDE_KERNEL' var 2022-01-07 19:19:15 +11:00
slabinfo.c misc: fixed several inconsistencies in email addresses 2022-01-08 07:15:59 +11:00
slabinfo.h misc: fixed several inconsistencies in email addresses 2022-01-08 07:15:59 +11:00
stat.c misc: amend the man page & source file copyright dates 2022-01-07 19:19:15 +11:00
stat.h misc: amend the man page & source file copyright dates 2022-01-07 19:19:15 +11:00
sysinfo.c library: this is why we hate those darn tab characters 2021-11-14 16:23:07 +11:00
test_Itemtables.c build-sys: proper fix for the 'test_Itemtables' module 2020-08-18 10:19:53 +10:00
test_namespace.c all: make buildable again for new 'misc.h' header file 2021-01-21 17:30:25 +11:00
test_pids.c testsuite: Correct include 2020-07-05 21:18:36 +10:00
test_sysinfo.c all: make buildable again for new 'misc.h' header file 2021-01-21 17:30:25 +11:00
test_uptime.c misc: Update Craig's email 2021-01-21 17:37:48 +11:00
test_version.c misc: Update Craig's email 2021-01-21 17:37:48 +11:00
uptime.c lib: Initialise uptime variables 2021-11-02 17:23:37 +11:00
version.c misc: Update Craig's email 2021-01-21 17:37:48 +11:00
vmstat.c misc: amend the man page & source file copyright dates 2022-01-07 19:19:15 +11:00
vmstat.h misc: amend the man page & source file copyright dates 2022-01-07 19:19:15 +11:00
wchan.c library: ensure thread safety for all static variables 2021-10-02 12:55:31 +10:00
wchan.h library: standardize 'pointer-to-thing' whitespace use 2021-07-27 21:17:18 +10:00
xtra-procps-debug.h misc: amend the man page & source file copyright dates 2022-01-07 19:19:15 +11:00