]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
[gdb/ada] Handle shrink resize in replace_operator_with_call
authorTom de Vries <tdevries@suse.de>
Mon, 7 Dec 2020 08:07:32 +0000 (09:07 +0100)
committerTom de Vries <tdevries@suse.de>
Mon, 7 Dec 2020 08:07:32 +0000 (09:07 +0100)
commitf51f9f1d0300029d33ecb73976f5d2be9b63553e
treeda77fac6d0af66cdb553d6717f498f52b758e5d5
parent00158a68d1c382f9afe16630ac327695a4904556
[gdb/ada] Handle shrink resize in replace_operator_with_call

In replace_operator_with_call, we resize the elts array like this:
...
  exp->nelts = exp->nelts + 7 - oplen;
  exp->resize (exp->nelts);
...

Although all the current callers ensure that the new size is bigger, it could
also be smaller, in which case the following memmove possibly reads out of
bounds:
...
   memmove (exp->elts + pc + 7, exp->elts + pc + oplen,
           EXP_ELEM_TO_BYTES (save_nelts - pc - oplen));
...

Fix this by doing the resize after the memmove in case the new size is
smaller.

Tested on x86_64-linux.

gdb/ChangeLog:

2020-12-07  Tom de Vries  <tdevries@suse.de>

* ada-lang.c (replace_operator_with_call): Handle shrink resize.
gdb/ChangeLog
gdb/ada-lang.c