Re: [PATCH] [gdb] Fix heap-buffer-overflow in args_complete_p

Tom de Vries
2026-01-06T14:52:12Z

On 1/5/26 5:38 PM, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
>
> Tom> + auto at = [&] (const char *s)
> Tom> + {
> Tom> + return s > end ? '\0' : *s;
> Tom> + };
>
> I think it would better to avoid stepping off the end at the points
> where the pointer is incremented.
>
> Tom> + while (at (input) != '\0')
>
> Like this could be
>
> for (input = skip_spaces (input); *input != '\0'; input = skip_spaces (input))
>
> and then there's like one or two spots to check in the loop.

I've submitted a v2 (
https://sourceware.org/pipermail/gdb-patches/2026-January/223715.html ).
I didn't do the transformation you suggested here, I tried to do
something minimal.

I could submit a follow-up patch to do some refactoring in this
function, though I'd likely do something like:
...
while (true)
{
input = skip_spaces (input);
if (*input == '\0')
break;
...
instead of the for loop you're suggesting.

Thanks,
- Tom