From 6acf0b3843737f9f95298465fdcf0d532c1995a4 Mon Sep 17 00:00:00 2001 From: Uros Bizjak Date: Thu, 9 Nov 2006 20:41:36 +0100 Subject: [PATCH] env.c (parse_schedule): Reject out of range values. * env.c (parse_schedule): Reject out of range values. (parse_unsigned_long): Reject out of range, negative or zero values. From-SVN: r118626 --- libgomp/ChangeLog | 6 ++++++ libgomp/env.c | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog index 139b7fc5c1b..d0e94d27268 100644 --- a/libgomp/ChangeLog +++ b/libgomp/ChangeLog @@ -1,3 +1,9 @@ +2006-11-09 Uros Bizjak + + * env.c (parse_schedule): Reject out of range values. + (parse_unsigned_long): Reject out of range, negative or zero values. + + 2006-10-29 Jakub Jelinek PR fortran/29629 diff --git a/libgomp/env.c b/libgomp/env.c index 0a80b87c5f5..af7e0c5c813 100644 --- a/libgomp/env.c +++ b/libgomp/env.c @@ -49,6 +49,7 @@ static void parse_schedule (void) { char *env, *end; + unsigned long value; env = getenv ("OMP_SCHEDULE"); if (env == NULL) @@ -85,11 +86,17 @@ parse_schedule (void) if (*env == '\0') goto invalid; - gomp_run_sched_chunk = strtoul (env, &end, 10); + errno = 0; + value = strtoul (env, &end, 10); + if (errno) + goto invalid; + while (isspace ((unsigned char) *end)) ++end; if (*end != '\0') goto invalid; + + gomp_run_sched_chunk = value; return; unknown: @@ -99,7 +106,6 @@ parse_schedule (void) invalid: gomp_error ("Invalid value for chunk size in " "environment variable OMP_SCHEDULE"); - gomp_run_sched_chunk = 1; return; } @@ -121,7 +127,11 @@ parse_unsigned_long (const char *name, unsigned long *pvalue) if (*env == '\0') goto invalid; + errno = 0; value = strtoul (env, &end, 10); + if (errno || (long) value <= 0) + goto invalid; + while (isspace ((unsigned char) *end)) ++end; if (*end != '\0')