From aef6890de1b939249000432022bf4a0e1c6d2d05 Mon Sep 17 00:00:00 2001 From: albert <> Date: Sat, 21 Dec 2002 11:27:47 +0000 Subject: [PATCH] allocate mem 1st --- Makefile | 6 +++--- proc/readproc.c | 14 +++++++++----- procps.lsm | 6 +++--- procps.spec | 2 +- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index c6069e64..40b40685 100644 --- a/Makefile +++ b/Makefile @@ -18,9 +18,9 @@ VERSION := 3 SUBVERSION := 1 -MINORVERSION := 4 -TARVERSION := 3.1.4 -LIBVERSION := 3.1.4 +MINORVERSION := 5 +TARVERSION := 3.1.5 +LIBVERSION := 3.1.5 ############ vars diff --git a/proc/readproc.c b/proc/readproc.c index 27b8c6ef..356c6a68 100644 --- a/proc/readproc.c +++ b/proc/readproc.c @@ -368,6 +368,7 @@ proc_t* readproc(PROCTAB* PT, proc_t* p) { #ifdef FLASK_LINUX security_id_t secsid; #endif + pid_t pid; // saved until we have a proc_t allocated for sure /* loop until a proc matching restrictions is found or no more processes */ /* I know this could be a while loop -- this way is easier to indent ;-) */ @@ -377,9 +378,8 @@ next_proc: /* get next PID for consideration */ #define flags (PT->flags) if (flags & PROC_PID) { - pid_t pid = *(PT->pids)++; + pid = *(PT->pids)++; if (unlikely(!pid)) return NULL; - p->pid = pid; snprintf(path, sizeof path, "/proc/%d", pid); } else { /* get next numeric /proc ent */ for (;;) { @@ -387,7 +387,7 @@ next_proc: /* get next PID for consideration */ if(unlikely(unlikely(!ent) || unlikely(!ent->d_name))) return NULL; if(likely( likely(*ent->d_name > '0') && likely(*ent->d_name <= '9') )) break; } - p->pid = strtoul(ent->d_name, NULL, 10); + pid = strtoul(ent->d_name, NULL, 10); memcpy(path, "/proc/", 6); strcpy(path+6, ent->d_name); // trust /proc to not contain evil top-level entries // snprintf(path, sizeof path, "/proc/%s", ent->d_name); @@ -404,11 +404,12 @@ next_proc: /* get next PID for consideration */ if (!p) p = xcalloc(p, sizeof *p); /* passed buf or alloced mem */ - p->euid = sb.st_uid; /* need a way to get real uid */ + p->euid = sb.st_uid; /* need a way to get real uid */ #ifdef FLASK_LINUX p->secsid = secsid; #endif + p->pid = pid; if (flags & PROC_FILLSTAT) { /* read, parse /proc/#/stat */ if (unlikely( file2str(path, "stat", sbuf, sizeof sbuf) == -1 )) @@ -478,6 +479,7 @@ proc_t* ps_readproc(PROCTAB* PT, proc_t* p) { #ifdef FLASK_LINUX security_id_t secsid; #endif + pid_t pid; // saved until we have a proc_t allocated for sure /* loop until a proc matching restrictions is found or no more processes */ /* I know this could be a while loop -- this way is easier to indent ;-) */ @@ -491,7 +493,7 @@ next_proc: /* get next PID for consideration */ if(unlikely(unlikely(!ent) || unlikely(!ent->d_name))) return NULL; if(likely( likely(*ent->d_name > '0') && likely(*ent->d_name <= '9') )) break; } - p->pid = strtoul(ent->d_name, NULL, 10); + pid = strtoul(ent->d_name, NULL, 10); memcpy(path, "/proc/", 6); strcpy(path+6, ent->d_name); // trust /proc to not contain evil top-level entries // snprintf(path, sizeof path, "/proc/%s", ent->d_name); @@ -505,10 +507,12 @@ next_proc: /* get next PID for consideration */ if (!p) p = xcalloc(p, sizeof *p); /* passed buf or alloced mem */ + p->euid = sb.st_uid; /* need a way to get real uid */ #ifdef FLASK_LINUX p->secsid = secsid; #endif + p->pid = pid; if ((file2str(path, "stat", sbuf, sizeof sbuf)) == -1) goto next_proc; /* error reading /proc/#/stat */ diff --git a/procps.lsm b/procps.lsm index 1815181f..fd78b87e 100644 --- a/procps.lsm +++ b/procps.lsm @@ -1,6 +1,6 @@ Begin4 Title: procps -Version: 3.1.4 +Version: 3.1.5 Entered-date: 2002-12-14 Description: Linux system utilities Keywords: procps /proc libproc sysctl pmap @@ -8,8 +8,8 @@ Keywords: procps /proc libproc sysctl pmap Author: Albert Cahalan, Michael K. Johnson, Jim Warner, etc. Maintained-by: various Primary-site: http://procps.sf.net/ - 236kB procps-3.1.4.tar.gz + 236kB procps-3.1.5.tar.gz Alternate-site: http://www.debian.org/Packages/unstable/base/procps.html - 236kB procps-3.1.4.tar.gz + 236kB procps-3.1.5.tar.gz Copying-policy: mixed End diff --git a/procps.spec b/procps.spec index d0793f1e..6674608e 100644 --- a/procps.spec +++ b/procps.spec @@ -3,7 +3,7 @@ Summary: System and process monitoring utilities Name: procps %define major_version 3 %define minor_version 1 -%define revision 4 +%define revision 5 %define version %{major_version}.%{minor_version}.%{revision} Version: %{version} Release: 1