Commit
012d44268695 effectively made peXXigen.c _bfd_XXi_swap_aux_out
always use the COFF E_FILNMLEN of 14. The problem was that the auxent
x_fname field was defined in include/coff/external.h using a length of
14. Later, E_FILNMLEN is redefined to 18 in coff/pe.h. This no doubt
falsely tripped memory checking tools. AUXESZ is 18, so no actual
buffer overrun.
This patch defines x_fname as an 18 char field, the full auxent, and
uses E_FILNMLEN when accessing.
PR 33302
include/
* coff/external.h (union external_auxent): Make x_fname
AUXESZ chars.
bfd/
* coffswap.h (coff_swap_aux_in): Correct #error message.
(coff_swap_aux_out): Likewise. Use E_FILNMLEN when copying
to ext field.
* peXXigen.c (_bfd_XXi_swap_aux_in): Add #error. Style fix.
(_bfd_XXi_swap_aux_out): Add #error. Don't use sizeof, use
E_FILNMLEN when copying to ext field.
gas
* testsuite/gas/pe/long_file_symbol.d,
* testsuite/gas/pe/long_file_symbol.s: New test.
* testsuite/gas/pe/pe.exp: Run it.
Reported-By: Frediano Ziglio <freddy77@gmail.com>
in->x_file.x_n.x_n.x_offset = H_GET_32 (abfd, ext->x_file.x_n.x_offset);
}
else
- {
#if FILNMLEN != E_FILNMLEN
-#error we need to cope with truncating or extending FILNMLEN
-#else
- memcpy (in->x_file.x_n.x_fname, ext->x_file.x_fname, FILNMLEN);
+#error we need to cope with truncating or extending x_fname
#endif
- }
+ memcpy (in->x_file.x_n.x_fname, ext->x_file.x_fname, FILNMLEN);
goto end;
case C_STAT:
H_PUT_32 (abfd, in->x_file.x_n.x_n.x_offset, ext->x_file.x_n.x_offset);
}
else
- {
#if FILNMLEN != E_FILNMLEN
-#error we need to cope with truncating or extending FILNMLEN
-#else
- memcpy (ext->x_file.x_fname, in->x_file.x_n.x_fname, FILNMLEN);
+#error we need to cope with truncating or extending xfname
#endif
- }
+ memcpy (ext->x_file.x_fname, in->x_file.x_n.x_fname, E_FILNMLEN);
goto end;
case C_STAT:
/* PR 17521: Make sure that all fields in the aux structure
are initialised. */
- memset (in, 0, sizeof * in);
+ memset (in, 0, sizeof (*in));
switch (in_class)
{
case C_FILE:
in->x_file.x_n.x_n.x_offset = H_GET_32 (abfd, ext->x_file.x_n.x_offset);
}
else
+#if FILNMLEN != E_FILNMLEN
+#error we need to cope with truncating or extending x_fname
+#endif
memcpy (in->x_file.x_n.x_fname, ext->x_file.x_fname, FILNMLEN);
return;
H_PUT_32 (abfd, in->x_file.x_n.x_n.x_offset, ext->x_file.x_n.x_offset);
}
else
- memcpy (ext->x_file.x_fname, in->x_file.x_n.x_fname, sizeof (ext->x_file.x_fname));
+#if FILNMLEN != E_FILNMLEN
+#error we need to cope with truncating or extending x_fname
+#endif
+ memcpy (ext->x_file.x_fname, in->x_file.x_n.x_fname, E_FILNMLEN);
return AUXESZ;
--- /dev/null
+#nm: -a
+
+#...
+.* long_file_symbol.s
+#pass
--- /dev/null
+ .file "long_file_symbol.s"
run_dump_test "aligncomm-b"
run_dump_test "aligncomm-c"
run_dump_test "aligncomm-d"
-
+run_dump_test "long_file_symbol"
run_dump_test "section-align-1"
run_dump_test "section-align-3"
run_dump_test "section-exclude"
union
{
- char x_fname[E_FILNMLEN];
+ /* Make x_fname the full auxent size, so that if coff/pe.h
+ redefines E_FILNMLEN from 14 to 18 we don't trigger sanitisers
+ accessing x_fname. Beware use of sizeof (x_file.x_fname). */
+ char x_fname[AUXESZ];
struct
{