This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[libgomp, patch, committed] backport verification of user input to 4.2


Committed as obvious to 4.2 branch.

2006-12-18  Daniel Franke  <franke.daniel@gmail.com>

        Backport from mainline:
        2006-12-04  Daniel Franke  <franke.daniel@gmail.com>

        PR libgomp/29949
        * env.c (omp_set_num_threads): Set illegal thread count to 1.

        Backport from mainline:
        2006-11-09  Uros Bizjak  <ubizjak@gmail.com>

        * env.c (parse_schedule): Reject out of range values.
        (parse_unsigned_long): Reject out of range, negative
        or zero values.


Bootstrapped and regtested on i686-pc-linux-gnu.

Regards
	Daniel

Index: env.c
===================================================================
--- env.c	(revision 116210)
+++ env.c	(revision 119511)
@@ -49,6 +49,7 @@
 parse_schedule (void)
 {
   char *env, *end;
+  unsigned long value;
 
   env = getenv ("OMP_SCHEDULE");
   if (env == NULL)
@@ -85,11 +86,17 @@
   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 @@
  invalid:
   gomp_error ("Invalid value for chunk size in "
 	      "environment variable OMP_SCHEDULE");
-  gomp_run_sched_chunk = 1;
   return;
 }
 
@@ -121,7 +127,11 @@
   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')
@@ -215,7 +225,7 @@
 void
 omp_set_num_threads (int n)
 {
-  gomp_nthreads_var = n;
+  gomp_nthreads_var = (n > 0 ? n : 1);
 }
 
 void

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]