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, sigar_proc_args_t *procargs,
int timestamp) int timestamp)
{ {
char buffer[9086], *args, *arg; char buffer[9086], *args=NULL, *arg;
sigar_cache_entry_t *ent; sigar_cache_entry_t *ent;
FILE *fp; FILE *fp;
pargs_t *pargs; 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); args = sigar_skip_multiple_token(args, 4);
SIGAR_SKIP_SPACE(args); SIGAR_SKIP_SPACE(args);
len = strlen(args); len = strlen(args);
args[len-1] = '\0'; /* chop \n */ if (len > 0) {
args[len-1] = '\0'; /* chop \n */
}
pargs->args = malloc(len+1); pargs->args = malloc(len+1);
memcpy(pargs->args, args, len); memcpy(pargs->args, args, len);
} }
pclose(fp); pclose(fp);
if (!args) {
return ESRCH;
}
} }
sigar_proc_args_create(procargs); sigar_proc_args_create(procargs);