From 02ddbf19cd251c6a403374a52a757b663769e9a6 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sun, 11 Mar 2007 22:44:30 +0000 Subject: [PATCH] validate string to pid conversion --- src/sigar_ptql.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/sigar_ptql.c b/src/sigar_ptql.c index d58c30c9..6a68bc90 100644 --- a/src/sigar_ptql.c +++ b/src/sigar_ptql.c @@ -589,9 +589,9 @@ enum { }; #ifdef SIGAR_64BIT -#define str2pid(value) strtoull(value, NULL, 10) +#define str2pid(value, ptr) strtoull(value, &ptr, 10) #else -#define str2pid(value) strtoul(value, NULL, 10) +#define str2pid(value, ptr) strtoul(value, &ptr, 10) #endif static int ptql_branch_init_pid(ptql_parse_branch_t *parsed, @@ -603,7 +603,11 @@ static int ptql_branch_init_pid(ptql_parse_branch_t *parsed, branch->data.pid = getpid(); } else { - branch->data.pid = str2pid(parsed->value); + char *ptr; + branch->data.pid = str2pid(parsed->value, ptr); + if (strtonum_failed(parsed->value, ptr)) { + return SIGAR_PTQL_MALFORMED_QUERY; + } } return SIGAR_OK; }