* corelow.c (core_open): Don't update the to_sections and
authorJeff Law <law@redhat.com>
Thu, 12 Oct 1995 23:26:06 +0000 (23:26 +0000)
committerJeff Law <law@redhat.com>
Thu, 12 Oct 1995 23:26:06 +0000 (23:26 +0000)
        to_sections_end fields in core_ops here.  It's too late.
        * irix5-nat.c (solib_add): Update the to_sections and
        to_sections_end fields in core_ops here if needed.
        * osfsolib.c (solib_add): Likewise.
        * rs6000-nat.c (xcoff_reload_core): Likewise.
        * solib.c (solib_add): Likewise.
        * somsolib.c (solib_add): Likewise.

gdb/ChangeLog
gdb/corelow.c
gdb/irix5-nat.c
gdb/osfsolib.c
gdb/rs6000-nat.c
gdb/somsolib.c

index 295de22325b758db8da53b406aef30b7ec5ef700..350f7119e8b0b1be9464362d6b4066e8fa8ce80d 100644 (file)
@@ -1,3 +1,14 @@
+Thu Oct 12 13:36:15 1995  Jeffrey A Law  (law@cygnus.com)
+
+       * corelow.c (core_open): Don't update the to_sections and
+       to_sections_end fields in core_ops here.  It's too late.
+       * irix5-nat.c (solib_add): Update the to_sections and
+       to_sections_end fields in core_ops here if needed.
+       * osfsolib.c (solib_add): Likewise.
+       * rs6000-nat.c (xcoff_reload_core): Likewise.
+       * solib.c (solib_add): Likewise.
+       * somsolib.c (solib_add): Likewise.
+
 Wed Oct 11 17:25:59 1995  Fred Fish  <fnf@rtl.cygnus.com>
 
        * Makefile.in (VERSION): Bump version to 4.15.1
index 014ef1024f8b257e2ed41f3e0f4d4f2d486a7485..d9370574f564a7bb88641e00c33581d65cd0280d 100644 (file)
@@ -210,13 +210,6 @@ core_open (filename, from_tty)
 #ifdef SOLIB_ADD
       catch_errors (solib_add_stub, &from_tty, (char *)0,
                    RETURN_MASK_ALL);
-
-      /* solib_add_stub usually modifies current_target.to_sections, which
-        has to be reflected in core_ops to enable proper freeing of
-        the to_sections vector in core_close and correct section
-        mapping in xfer_memory and core_files_info.  */
-      core_ops.to_sections = current_target.to_sections;
-      core_ops.to_sections_end = current_target.to_sections_end;
 #endif
 
       /* Now, set up the frame cache, and print the top of stack.  */
index 3bfaef7d714c43160d66b8ecdaa2954099c855ad..3ba00b1017e15c58d5aa2f8233e8776d091c0d58 100644 (file)
@@ -621,6 +621,13 @@ solib_add (arg_string, from_tty, target)
       
       if (count)
        {
+         int update_coreops;
+
+         /* We must update the to_sections field in the core_ops structure
+            here, otherwise we dereference a potential dangling pointer
+            for each call to target_read/write_memory within this routine.  */
+         update_coreops = core_ops.to_sections == target->to_sections;
+            
          /* Reallocate the target's section table including the new size.  */
          if (target -> to_sections)
            {
@@ -637,6 +644,14 @@ solib_add (arg_string, from_tty, target)
            }
          target -> to_sections_end = target -> to_sections + (count + old);
          
+         /* Update the to_sections field in the core_ops structure
+            if needed.  */
+         if (update_coreops)
+           {
+             core_ops.to_sections = target->to_sections;
+             core_ops.to_sections_end = target->to_sections_end;
+           }
+
          /* Add these section table entries to the target's table.  */
          while ((so = find_solib (so)) != NULL)
            {
index 86d9606c9a02e1934df1228e761398b7f13b3bc9..d2b55302e96465cc58149ce68983090c05857fc8 100644 (file)
@@ -625,6 +625,13 @@ solib_add (arg_string, from_tty, target)
       
       if (count)
        {
+         int update_coreops;
+
+         /* We must update the to_sections field in the core_ops structure
+            here, otherwise we dereference a potential dangling pointer
+            for each call to target_read/write_memory within this routine.  */
+         update_coreops = core_ops.to_sections == target->to_sections;
+            
          /* Reallocate the target's section table including the new size.  */
          if (target -> to_sections)
            {
@@ -641,6 +648,14 @@ solib_add (arg_string, from_tty, target)
            }
          target -> to_sections_end = target -> to_sections + (count + old);
          
+         /* Update the to_sections field in the core_ops structure
+            if needed.  */
+         if (update_coreops)
+           {
+             core_ops.to_sections = target->to_sections;
+             core_ops.to_sections_end = target->to_sections_end;
+           }
+
          /* Add these section table entries to the target's table.  */
          while ((so = find_solib (so)) != NULL)
            {
index 996cba9fe7001d89f0ea15a80fa8ff866dddb16d..e6e90ee0ffe6333505f8667b0950ae86909a0080 100644 (file)
@@ -738,6 +738,11 @@ xcoff_relocate_core (target)
        {
          int count;
          struct section_table *stp;
+         int update_coreops;
+
+         /* We must update the to_sections field in the core_ops structure
+            now to avoid dangling pointer dereferences.  */
+         update_coreops = core_ops.to_sections === target->to_sections;
          
          count = target->to_sections_end - target->to_sections;
          count += 2;
@@ -745,6 +750,14 @@ xcoff_relocate_core (target)
            xrealloc (target->to_sections,
                      sizeof (struct section_table) * count);
          target->to_sections_end = target->to_sections + count;
+
+         /* Update the to_sections field in the core_ops structure
+            if needed.  */
+         if (update_coreops)
+           {
+             core_ops.to_sections = target->to_sections;
+             core_ops.to_sections_end = target->to_sections_end;
+           }
          stp = target->to_sections_end - 2;
 
          /* "Why do we add bfd_section_vma?", I hear you cry.
index 16d9fa0a44ddc3c34424a1fc9be6bb7915a6d2e9..2744e5c9a048d2c0251de354c9e57be9bfa6651b 100644 (file)
@@ -405,6 +405,12 @@ som_solib_add (arg_string, from_tty, target)
       if (status != 0)
        {
          int old, new;
+         int update_coreops;
+
+         /* We must update the to_sections field in the core_ops structure
+            here, otherwise we dereference a potential dangling pointer
+            for each call to target_read/write_memory within this routine.  */
+         update_coreops = core_ops.to_sections == target->to_sections;
 
          new = new_so->sections_end - new_so->sections;
          /* Add sections from the shared library to the core target.  */
@@ -422,6 +428,16 @@ som_solib_add (arg_string, from_tty, target)
                xmalloc ((sizeof (struct section_table)) * new);
            }
          target->to_sections_end = (target->to_sections + old + new);
+
+         /* Update the to_sections field in the core_ops structure
+            if needed.  */
+         if (update_coreops)
+           {
+             core_ops.to_sections = target->to_sections;
+             core_ops.to_sections_end = target->to_sections_end;
+           }
+
+         /* Copy over the old data before it gets clobbered.  */
          memcpy ((char *)(target->to_sections + old),
                  new_so->sections,
                  ((sizeof (struct section_table)) * new));