From ea6b08a70f6ab28430d20c1e3617f3e121c3a76a Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Fri, 7 Oct 2005 18:20:44 +0000 Subject: [PATCH] prevent out-of-bounds read/write if proc arg happens to be > 1024 --- src/os/solaris/solaris_sigar.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/os/solaris/solaris_sigar.c b/src/os/solaris/solaris_sigar.c index 4f2ed810..4e6a0f0b 100644 --- a/src/os/solaris/solaris_sigar.c +++ b/src/os/solaris/solaris_sigar.c @@ -746,7 +746,7 @@ int sigar_proc_args_get(sigar_t *sigar, sigar_pid_t pid, int alen; char *arg; - if ((nread = pread(fd, buffer, sizeof(buffer), (off_t)argvp[n])) <= 0) { + if ((nread = pread(fd, buffer, sizeof(buffer)-1, (off_t)argvp[n])) <= 0) { close(fd); if (argvp != argvb) { free(argvp); @@ -754,7 +754,8 @@ int sigar_proc_args_get(sigar_t *sigar, sigar_pid_t pid, sigar_proc_args_destroy(sigar, procargs); return errno; } - + /* chances of arg > 1024 are slim, but just incase. */ + buffer[nread] = '\0'; alen = strlen(buffer)+1; arg = malloc(alen); memcpy(arg, buffer, alen);