From e554a35a0effa6df09db246a9987c0a337cb3bb5 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sun, 31 Dec 2006 17:31:04 +0000 Subject: [PATCH] prevent possible segfault in proc_args --- src/os/solaris/solaris_sigar.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/os/solaris/solaris_sigar.c b/src/os/solaris/solaris_sigar.c index df971927..af8c35f8 100644 --- a/src/os/solaris/solaris_sigar.c +++ b/src/os/solaris/solaris_sigar.c @@ -791,7 +791,7 @@ static int ucb_ps_args_get(sigar_t *sigar, sigar_pid_t pid, sigar_proc_args_t *procargs, int timestamp) { - char buffer[9086], *args, *arg; + char buffer[9086], *args=NULL, *arg; sigar_cache_entry_t *ent; FILE *fp; pargs_t *pargs; @@ -838,13 +838,19 @@ static int ucb_ps_args_get(sigar_t *sigar, sigar_pid_t pid, args = sigar_skip_multiple_token(args, 4); SIGAR_SKIP_SPACE(args); len = strlen(args); - args[len-1] = '\0'; /* chop \n */ + if (len > 0) { + args[len-1] = '\0'; /* chop \n */ + } pargs->args = malloc(len+1); memcpy(pargs->args, args, len); } pclose(fp); + + if (!args) { + return ESRCH; + } } sigar_proc_args_create(procargs);