]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[Morello/gdbserver] Fix incorrect vector resize operation
authorLuis Machado <luis.machado@arm.com>
Fri, 11 Aug 2023 06:54:25 +0000 (07:54 +0100)
committerLuis Machado <luis.machado@arm.com>
Fri, 11 Aug 2023 06:54:25 +0000 (07:54 +0100)
This patch fixes an incorrect vector resize operation when reading the auxv.  A
mistake makes the current code copy data over the end of the vector buffer,
leading to memory corruption.

Fix this by having a pointer to the end of the vector buffer before resizing the
took place.

gdbserver/linux-low.cc

index 110be634f310d6e5a27e3f83f5fa9bc30bb4de20..34bba30a8b881dbfecb1781a3daf7da3c7cc3182 100644 (file)
@@ -5788,14 +5788,17 @@ linux_process_target::get_auxv ()
        }
       else if (n < block_size)
        {
-         /* We're done reading data.  */
+         /* We're done reading data.  Shrink the vector to fit the right size
+            of the auxv data.  */
          auxv.resize (auxv.size () - (block_size - n));
          done = true;
        }
       else
        {
+         /* Enlarge the vector so we can fit another chunk of auxv data.  */
+         size_t old_size = auxv.size ();
          auxv.resize (auxv.size () + block_size);
-         ptr = auxv.data () + auxv.size ();
+         ptr = auxv.data () + old_size;
        }
     }