From 30bb26f896777144eb20a620440a97fa5c2be50f Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 13 Apr 2017 07:21:15 +0000 Subject: Fix s6-ps types parsing The documented type lengths for /proc/$pid/stat in "man 5 proc" are for *kernel* types. Those lengths may not apply to userland types (think 32-bit userspace on 64-bit kernels). So we need to parse everything as 64-bit, and do the conversion to userspace types later. Thanks to mixi for the report and the analysis. --- src/minutils/s6ps_statparse.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/minutils/s6ps_statparse.c b/src/minutils/s6ps_statparse.c index 0b1b261..56e00f9 100644 --- a/src/minutils/s6ps_statparse.c +++ b/src/minutils/s6ps_statparse.c @@ -9,6 +9,7 @@ #include #include "s6-ps.h" + /* going to great lengths to avoid scanf(), but all this code is still smaller than scanf (no floating point parsing etc.) @@ -25,7 +26,7 @@ static size_t f64 (char const *s, void *u64) return uint64_scan(s, u) ; } -#define DEFUN(name, type) \ +#define DEFUNU(name, type) \ static size_t name (char const *s, void *p) \ { \ uint64_t u ; \ @@ -34,9 +35,18 @@ static size_t name (char const *s, void *p) \ return len ; \ } \ -DEFUN(fint, int) -DEFUN(fpid, pid_t) -DEFUN(fdev, dev_t) +#define DEFUNS(name, type) \ +static size_t name (char const *s, void *p) \ +{ \ + int64_t d ; \ + size_t len = int64_scan(s, &d) ; \ + *(type *)p = d ; \ + return len ; \ +} \ + +DEFUNS(fint, int) +DEFUNS(fpid, pid_t) +DEFUNU(fdev, dev_t) static scanfunc_t_ref scanfuncs[STATVARS] = { -- cgit v1.2.3