[PATCH v3 05/26] readelf: last tag as empty string triggers corrupt string data incorrectly
Richard Earnshaw
Richard.Earnshaw@arm.com
Tue Jun 10 17:22:37 GMT 2025
On 09/05/2025 16:12, Matthieu Longo wrote:
> ---
> binutils/readelf.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/binutils/readelf.c b/binutils/readelf.c
> index dd1871d8c75..88edf9246cc 100644
> --- a/binutils/readelf.c
> +++ b/binutils/readelf.c
> @@ -17779,12 +17779,14 @@ display_tag_value (signed int tag,
> else if (tag & 1)
> {
> /* PR 17531 file: 027-19978-0.004. */
> - size_t maxlen = (end - p) - 1;
> + size_t maxlen = end - p;
>
> putchar ('"');
> if (maxlen > 0)
> {
> - print_symbol_name ((int) maxlen, (const char *) p);
> + maxlen -= 1; /* Remove \0 from the character count. */
> + if (maxlen > 0) /* Don't try to print an empty string. */
> + print_symbol_name ((int) maxlen, (const char *) p);
> p += strnlen ((char *) p, maxlen) + 1;
> }
> else
This looks sensible, but it's outside my scope as a port maintainer.
Really, though, this should be sent as a separate patch as it's not
directly related to the rest of the series.
A better commit message that doesn't try to write everything in the
summary line would help here too; then you aren't constrained to keeping
everything under ~70 chars and can write proper sentences.
R.
More information about the Binutils
mailing list