[PATCH v2] PE/COFF: raise normal PE section limit safely
Jan Beulich
jbeulich@suse.com
Fri Jul 3 09:43:51 GMT 2026
On 01.07.2026 19:58, Oleg Tolmatcev wrote:
> --- a/bfd/peXXigen.c
> +++ b/bfd/peXXigen.c
> @@ -109,12 +109,70 @@
> #define SetHighBit(val) ((val) | 0x80000000)
> #define WithoutHighBit(val) ((val) & 0x7fffffff)
>
> +static bool
> +pe_decode_sym_section_number (bfd *abfd, const char *raw_scnum, int *scnump)
> +{
> + unsigned int scnum = H_GET_16 (abfd, raw_scnum);
> +
> + switch (scnum)
> + {
> + case IMAGE_SYM_UNDEFINED:
> + *scnump = N_UNDEF;
> + return true;
> + case IMAGE_SYM_ABSOLUTE:
> + *scnump = N_ABS;
> + return true;
> + case IMAGE_SYM_DEBUG:
> + *scnump = N_DEBUG;
> + return true;
> + }
> +
> + if (scnum > IMAGE_SYM_SECTION_MAX)
> + {
> + _bfd_error_handler
> + /* xgettext:c-format */
> + (_("%pB: invalid PE symbol section number %#x"), abfd, scnum);
Mind me suggesting s/invalid/unrecognized/ ?
> + bfd_set_error (bfd_error_bad_value);
> + return false;
> + }
While returning an error here may make sense, ...
> @@ -124,7 +182,8 @@ _bfd_XXi_swap_sym_in (bfd * abfd, void * ext1, void * in1)
> memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN);
>
> in->n_value = H_GET_32 (abfd, ext->e_value);
> - in->n_scnum = (short) H_GET_16 (abfd, ext->e_scnum);
> + if (! pe_decode_sym_section_number (abfd, ext->e_scnum, &in->n_scnum))
> + return;
... that's of limited use here when the caller can't be told of the error.
I don't think bfd_set_error() has any respective effect, unless that
caller actively checked via bfd_get_error(). IOW I think you still need to
set *scnump in pe_decode_sym_section_number(), and bailing out here isn't
helpful.
Oh, there is the ->read_only flag in struct bfd which looks to exist for
purposes like this one. It's for objcopy / strip only though, so in
particular ld could still be in trouble.
Jan
More information about the Binutils
mailing list