aboutsummaryrefslogtreecommitdiff
path: root/binutils/dwarf.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2021-05-15 14:36:26 +0930
committerAlan Modra <amodra@gmail.com>2021-05-15 14:36:54 +0930
commitfc5e0925d4bff79c8c036cf00803112a1ec04188 (patch)
treed71d622247fdaadaa710ece3fdce8bfb9ffc2289 /binutils/dwarf.c
parent7c96e6120f1b9b5025629bbe995ca55d1be8f36f (diff)
downloadgdb-fc5e0925d4bff79c8c036cf00803112a1ec04188.zip
gdb-fc5e0925d4bff79c8c036cf00803112a1ec04188.tar.gz
gdb-fc5e0925d4bff79c8c036cf00803112a1ec04188.tar.bz2
_mul_overflow and get_encoded_value
A sufficiently mad compiler optimiser can take undefined behaviour according to the C standard as an opportunity to remove code. Since "data + size" might be seen to be past the end of an array, calculating such an expression is UB. _mul_overflow is infrastructure for later patches. * bucomm.h (_mul_overflow): Define. * dwarf.c (get_encoded_value): Avoid pointer UB.
Diffstat (limited to 'binutils/dwarf.c')
-rw-r--r--binutils/dwarf.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index 2794a15..020b7e0 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -178,7 +178,7 @@ get_encoded_value (unsigned char **pdata,
unsigned int size = size_of_encoded_value (encoding);
dwarf_vma val;
- if (data + size >= end)
+ if (data >= end || size > (size_t) (end - data))
{
warn (_("Encoded value extends past end of section\n"));
* pdata = end;