]> granicus.if.org Git - gc/commitdiff
Check DATASTART is less than DATAEND even assertions off
authorIvan Maidanski <ivmai@mail.ru>
Mon, 26 Oct 2015 05:25:54 +0000 (08:25 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Mon, 26 Oct 2015 05:25:54 +0000 (08:25 +0300)
* dyn_load.c (GC_register_dynamic_libraries_dl_iterate_phdr):
Abort with the appropriate message if DATASTART is NULL or greater than
DATAEND (same for DATASTART2 and DATAEND2).
* os_dep.c (GC_init_linux_data_start, GC_register_data_segments):
Likewise.
* os_dep.c (GC_init_linux_data_start, GC_register_data_segments):
Remove assertion about DATASTART and DATAEND.
* os_dep.c (GC_init_linux_data_start): Code refactoring.

dyn_load.c
os_dep.c

index c8d051ab662d830e05a32a2f2ff94b0304053903..0afdb86a090352f406b941f8138e6a9967b6376f 100644 (file)
@@ -624,11 +624,20 @@ STATIC GC_bool GC_register_dynamic_libraries_dl_iterate_phdr(void)
 #     else
         dataend = DATAEND;
 #     endif
+      if (NULL == datastart || (word)datastart > (word)dataend)
+        ABORT_ARG2("Wrong DATASTART/END pair",
+                   ": %p .. %p", datastart, dataend);
 
       /* dl_iterate_phdr may forget the static data segment in  */
       /* statically linked executables.                         */
       GC_add_roots_inner(datastart, dataend, TRUE);
 #     if defined(DATASTART2)
+        if ((word)DATASTART2 - 1U >= (word)DATAEND2) {
+                        /* Subtract one to check also for NULL  */
+                        /* without a compiler warning.          */
+          ABORT_ARG2("Wrong DATASTART/END2 pair",
+                     ": %p .. %p", DATASTART2, DATAEND2);
+        }
         GC_add_roots_inner(DATASTART2, DATAEND2, TRUE);
 #     endif
   }
index 21b5d1eb9074ff82bd9cb2b152abc6cadc2f446c..9f44395f80d6caf140c60af5bb344e0c4a7f06d4 100644 (file)
--- a/os_dep.c
+++ b/os_dep.c
@@ -435,19 +435,18 @@ GC_INNER char * GC_get_maps(void)
             GC_log_printf(
                 "__data_start is wrong; using __dso_handle as data start\n");
 #         endif
-          GC_ASSERT((word)GC_data_start <= (word)data_end);
-          return;
-        }
+        } else
 #     endif
-      if ((ptr_t)__data_start != 0) {
-          GC_data_start = (ptr_t)(__data_start);
-          GC_ASSERT((word)GC_data_start <= (word)data_end);
-          return;
+      /* else */ if ((ptr_t)__data_start != 0) {
+        GC_data_start = (ptr_t)(__data_start);
+      } else {
+        GC_data_start = (ptr_t)(data_start);
       }
-      if ((ptr_t)data_start != 0) {
-          GC_data_start = (ptr_t)(data_start);
-          GC_ASSERT((word)GC_data_start <= (word)data_end);
-          return;
+      if (GC_data_start != NULL) {
+        if ((word)GC_data_start > (word)data_end)
+          ABORT_ARG2("Wrong __data_start/_end pair",
+                     ": %p .. %p", GC_data_start, data_end);
+        return;
       }
 #     ifdef DEBUG_ADD_DEL_ROOTS
         GC_log_printf("__data_start not provided\n");
@@ -1893,6 +1892,9 @@ void GC_register_data_segments(void)
   ptr_t region_start = DATASTART;
   ptr_t region_end;
 
+  if ((word)region_start - 1U >= (word)DATAEND)
+    ABORT_ARG2("Wrong DATASTART/END pair",
+               ": %p .. %p", region_start, DATAEND);
   for (;;) {
     region_end = GC_find_limit_openbsd(region_start, DATAEND);
     GC_add_roots_inner(region_start, region_end, FALSE);
@@ -1922,9 +1924,17 @@ void GC_register_data_segments(void)
             GC_add_roots_inner(DATASTART, p, FALSE);
         }
 #     else
-        GC_ASSERT(DATASTART);
+        if ((word)DATASTART - 1U >= (word)DATAEND) {
+                                /* Subtract one to check also for NULL  */
+                                /* without a compiler warning.          */
+          ABORT_ARG2("Wrong DATASTART/END pair",
+                     ": %p .. %p", DATASTART, DATAEND);
+        }
         GC_add_roots_inner(DATASTART, DATAEND, FALSE);
 #       if defined(DATASTART2)
+          if ((word)DATASTART2 - 1U >= (word)DATAEND2)
+            ABORT_ARG2("Wrong DATASTART/END2 pair",
+                       ": %p .. %p", DATASTART2, DATAEND2);
           GC_add_roots_inner(DATASTART2, DATAEND2, FALSE);
 #       endif
 #     endif