From efb74c1703fe3c8903a311ad940ab18b9da19592 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Tue, 29 Jan 2008 00:08:29 +0000 Subject: [PATCH] sanity check strchr results --- src/os/linux/linux_sigar.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/os/linux/linux_sigar.c b/src/os/linux/linux_sigar.c index 9870c664..bcd7345a 100644 --- a/src/os/linux/linux_sigar.c +++ b/src/os/linux/linux_sigar.c @@ -757,9 +757,12 @@ static int proc_stat_read(sigar_t *sigar, sigar_pid_t pid) return status; } - ptr = strchr(ptr, '(')+1; - - tmp = strrchr(ptr, ')'); + if (!(ptr = strchr(ptr, '('))) { + return EINVAL; + } + if (!(tmp = strrchr(++ptr, ')'))) { + return EINVAL; + } len = tmp-ptr; if (len >= sizeof(pstat->name)) {