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]

[gomp4] libgomp: Prevent NULL pointer dereference


Hi!

Committed to gomp-4_0-branch in r218848:

commit 8fbca6d4d703b08aed3e1c9ae7c227e6d123db24
Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Wed Dec 17 22:59:07 2014 +0000

    libgomp: Prevent NULL pointer dereference.
    
    	libgomp/
    	* target.c (GOMP_target, GOMP_target_data, GOMP_target_update):
    	Prevent NULL pointer dereference.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gomp-4_0-branch@218848 138bc75d-0d04-0410-961f-82ee72b054a4
---
 libgomp/ChangeLog.gomp |  3 +++
 libgomp/target.c       | 13 ++++++++-----
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git libgomp/ChangeLog.gomp libgomp/ChangeLog.gomp
index 6181f1a..b7a0e7d 100644
--- libgomp/ChangeLog.gomp
+++ libgomp/ChangeLog.gomp
@@ -1,6 +1,9 @@
 2014-12-17  Thomas Schwinge  <thomas@codesourcery.com>
 	    Tom de Vries  <tom@codesourcery.com>
 
+	* target.c (GOMP_target, GOMP_target_data, GOMP_target_update):
+	Prevent NULL pointer dereference.
+
 	* testsuite/lib/libgomp.exp: Set offload_targets_s, and
 	offload_targets_s_openacc.
 	(check_effective_target_openacc_nvidia_accel_selected): Look for
diff --git libgomp/target.c libgomp/target.c
index fc94e8f..bdfec67 100644
--- libgomp/target.c
+++ libgomp/target.c
@@ -840,7 +840,6 @@ GOMP_target (int device, void (*fn) (void *), const void *offload_table,
 	     unsigned char *kinds)
 {
   struct gomp_device_descr *devicep = resolve_device (device);
-  struct gomp_memory_mapping *mm = &devicep->mem_map;
 
   if (devicep != NULL && !devicep->is_initialized)
     gomp_init_dev_tables (devicep);
@@ -868,6 +867,7 @@ GOMP_target (int device, void (*fn) (void *), const void *offload_table,
     fn_addr = (void *) fn;
   else
     {
+      struct gomp_memory_mapping *mm = &devicep->mem_map;
       gomp_mutex_lock (&mm->lock);
       if (!devicep->is_initialized)
 	gomp_init_dev_tables (devicep);
@@ -905,7 +905,6 @@ GOMP_target_data (int device, const void *offload_table, size_t mapnum,
 		  void **hostaddrs, size_t *sizes, unsigned char *kinds)
 {
   struct gomp_device_descr *devicep = resolve_device (device);
-  struct gomp_memory_mapping *mm = &devicep->mem_map;
 
   if (devicep != NULL && !devicep->is_initialized)
     gomp_init_dev_tables (devicep);
@@ -928,6 +927,7 @@ GOMP_target_data (int device, const void *offload_table, size_t mapnum,
       return;
     }
 
+  struct gomp_memory_mapping *mm = &devicep->mem_map;
   gomp_mutex_lock (&mm->lock);
   if (!devicep->is_initialized)
     gomp_init_dev_tables (devicep);
@@ -958,14 +958,17 @@ GOMP_target_update (int device, const void *offload_table, size_t mapnum,
 		    void **hostaddrs, size_t *sizes, unsigned char *kinds)
 {
   struct gomp_device_descr *devicep = resolve_device (device);
+
+  if (devicep == NULL)
+    return;
+
   struct gomp_memory_mapping *mm = &devicep->mem_map;
-
   gomp_mutex_lock (&mm->lock);
-  if (devicep != NULL && !devicep->is_initialized)
+  if (!devicep->is_initialized)
     gomp_init_device (devicep);
   gomp_mutex_unlock (&mm->lock);
 
-  if (devicep != NULL && !(devicep->capabilities & TARGET_CAP_OPENMP_400))
+  if (!(devicep->capabilities & TARGET_CAP_OPENMP_400))
     return;
 
   gomp_update (devicep, &devicep->mem_map, mapnum, hostaddrs, sizes, kinds,


GrÃÃe,
 Thomas

Attachment: pgpIOWvjtsznf.pgp
Description: PGP signature


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