aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis Machado <luis.machado@arm.com>2023-08-11 07:54:25 +0100
committerLuis Machado <luis.machado@arm.com>2023-08-11 07:54:25 +0100
commite4c78b3b86fd2148c37d1870cf8bd663f49d4fe0 (patch)
tree9c0f1d67e5e717e80333264c1b3bb58317c3f568
parent459784def001e3d5b1b6a18246a5e01de2a357d2 (diff)
downloadgdb-e4c78b3b86fd2148c37d1870cf8bd663f49d4fe0.zip
gdb-e4c78b3b86fd2148c37d1870cf8bd663f49d4fe0.tar.gz
gdb-e4c78b3b86fd2148c37d1870cf8bd663f49d4fe0.tar.bz2
[Morello/gdbserver] Fix incorrect vector resize operation
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.
-rw-r--r--gdbserver/linux-low.cc7
1 files changed, 5 insertions, 2 deletions
diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc
index 110be63..34bba30 100644
--- a/gdbserver/linux-low.cc
+++ b/gdbserver/linux-low.cc
@@ -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;
}
}