From 4cfb042df9f3e035e610534a893566f3c83cbd61 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Wed, 18 Nov 2009 18:02:10 +0100 Subject: [PATCH] Fix bug in $pid_cmdline --- src/proc.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/proc.c b/src/proc.c index 50ee571..ae453b2 100644 --- a/src/proc.c +++ b/src/proc.c @@ -115,18 +115,22 @@ void print_pid_cmdline(struct text_object *obj, char *p, int p_max_size) char* buf; int i, bytes_read; - asprintf(&buf, PROCDIR "/%s/cmdline", obj->data.s); - strcpy(obj->data.s, buf); - free(buf); - buf = readfile(obj->data.s, &bytes_read, 1); - if(buf != NULL) { - for(i = 0; i < bytes_read-1; i++) { - if(buf[i] == 0) { - buf[i] = ' '; + if(*(obj->data.s) != 0) { + asprintf(&buf, PROCDIR "/%s/cmdline", obj->data.s); + strcpy(obj->data.s, buf); + free(buf); + buf = readfile(obj->data.s, &bytes_read, 1); + if(buf != NULL) { + for(i = 0; i < bytes_read-1; i++) { + if(buf[i] == 0) { + buf[i] = ' '; + } } + snprintf(p, p_max_size, "%s", buf); + free(buf); } - snprintf(p, p_max_size, "%s", buf); - free(buf); + } else { + NORM_ERR("$pid_cmdline didn't receive a argument"); } } -- 1.7.9.5