prevent possible segfault in proc_args

This commit is contained in:
Doug MacEachern 2006-12-31 17:31:04 +00:00
parent 0bf91e99ad
commit e554a35a0e
1 changed files with 8 additions and 2 deletions

View File

@ -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);
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);