binutils-gdb/ld/testsuite/ld-ctf
Nick Alcock 84f5c557a4 libctf, ld: diagnose corrupted CTF header cth_strlen
The last section in a CTF dict is the string table, at an offset
represented by the cth_stroff header field.  Its length is recorded in
the next field, cth_strlen, and the two added together are taken as the
size of the CTF dict.  Upon opening a dict, we check that none of the
header offsets exceed this size, and we check when uncompressing a
compressed dict that the result of the uncompression is the same length:
but CTF dicts need not be compressed, and short ones are not.
Uncompressed dicts just use the ctf_size without checking it.  This
field is thankfully almost unused: it is mostly used when reserializing
a dict, which can't be done to dicts read off disk since they're
read-only.

However, when opening an uncompressed foreign-endian dict we have to
copy it out of the mmaped region it is stored in so we can endian-
swap it, and we use ctf_size when doing that.  When the cth_strlen is
corrupt, this can overrun.

Fix this by checking the ctf_size in all uncompressed cases, just as we
already do in the compressed case.  Add a new test.

This came to light because various corrupted-CTF raw-asm tests had an
incorrect cth_strlen: fix all of them so they produce the expected
error again.

libctf/
	PR libctf/28933
	* ctf-open.c (ctf_bufopen_internal): Always check uncompressed
	CTF dict sizes against the section size in case the cth_strlen is
	corrupt.

ld/
	PR libctf/28933
	* testsuite/ld-ctf/diag-strlen-invalid.*: New test,
	derived from diag-cttname-invalid.s.
	* testsuite/ld-ctf/diag-cttname-invalid.s: Fix incorrect cth_strlen.
	* testsuite/ld-ctf/diag-cttname-null.s: Likewise.
	* testsuite/ld-ctf/diag-cuname.s: Likewise.
	* testsuite/ld-ctf/diag-parlabel.s: Likewise.
	* testsuite/ld-ctf/diag-parname.s: Likewise.
2022-03-23 13:48:32 +00:00
..
A-2.c
A.c
array-char.c
array-int.c
array.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
B-2.c
B.c
C-2.c
C.c
child-float.c
child-int.c
conflicting-cycle-1.B-1.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
conflicting-cycle-1.B-2.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
conflicting-cycle-1.parent.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
conflicting-cycle-2.A-1.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
conflicting-cycle-2.A-2.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
conflicting-cycle-2.parent.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
conflicting-cycle-3.C-1.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
conflicting-cycle-3.C-2.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
conflicting-cycle-3.parent.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
conflicting-enums.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
conflicting-typedefs.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
cross-tu-1.c
cross-tu-2.c
cross-tu-conflicting-2.c
cross-tu-cyclic-1.c
cross-tu-cyclic-2.c
cross-tu-cyclic-3.c
cross-tu-cyclic-4.c
cross-tu-cyclic-conflicting.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
cross-tu-cyclic-nonconflicting.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
cross-tu-into-cycle.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
cross-tu-noncyclic.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
ctf.exp Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
cycle-1.c
cycle-1.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
cycle-2.A.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
cycle-2.B.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
cycle-2.C.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
data-func-1.c
data-func-2.c libctf, ld: fix data symbol test with newer GCC 2021-01-19 12:45:18 +00:00
data-func-conflicted-vars.d include, libctf, ld: extend variable section to contain functions too 2022-03-23 13:48:32 +00:00
data-func-conflicted.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
diag-ctf-version-0.d
diag-ctf-version-0.s
diag-ctf-version-2-unsupported-feature.d
diag-ctf-version-2-unsupported-feature.s
diag-ctf-version-f.d
diag-ctf-version-f.s
diag-cttname-invalid.d
diag-cttname-invalid.s libctf, ld: diagnose corrupted CTF header cth_strlen 2022-03-23 13:48:32 +00:00
diag-cttname-null.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
diag-cttname-null.s libctf, ld: diagnose corrupted CTF header cth_strlen 2022-03-23 13:48:32 +00:00
diag-cuname.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
diag-cuname.s libctf, ld: diagnose corrupted CTF header cth_strlen 2022-03-23 13:48:32 +00:00
diag-decompression-failure.d
diag-decompression-failure.s
diag-parlabel.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
diag-parlabel.s libctf, ld: diagnose corrupted CTF header cth_strlen 2022-03-23 13:48:32 +00:00
diag-parname.d
diag-parname.s libctf, ld: diagnose corrupted CTF header cth_strlen 2022-03-23 13:48:32 +00:00
diag-strlen-invalid.d libctf, ld: diagnose corrupted CTF header cth_strlen 2022-03-23 13:48:32 +00:00
diag-strlen-invalid.s libctf, ld: diagnose corrupted CTF header cth_strlen 2022-03-23 13:48:32 +00:00
diag-unsupported-flag.d
diag-unsupported-flag.s
diag-wrong-magic-number-mixed.d libctf, ld: dump enums: generally improve dump formatting 2021-01-05 14:53:39 +00:00
diag-wrong-magic-number.d
diag-wrong-magic-number.s
enum-2.c
enum-forward.c libctf, ld: fix formatting of forwards to unions and enums 2021-01-05 14:53:40 +00:00
enum-forward.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
enum.c
enums.c libctf, ld: dump enums: generally improve dump formatting 2021-01-05 14:53:39 +00:00
enums.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
forward.c libctf, ld: prohibit getting the size or alignment of forwards 2021-01-05 14:53:39 +00:00
forward.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
function.c
function.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
nonrepresentable-1.c libctf, ld: fix test results for upstream GCC 2021-05-06 09:31:31 +01:00
nonrepresentable-2.c libctf, ld: fix test results for upstream GCC 2021-05-06 09:31:31 +01:00
nonrepresentable-member.c libctf, ld: handle nonrepresentable types better 2021-10-25 11:17:05 +01:00
nonrepresentable-member.d libctf, ld: handle nonrepresentable types better 2021-10-25 11:17:05 +01:00
nonrepresentable.d Adjust ld ctf test for 32-bit targets 2022-03-04 00:28:07 +10:30
slice.c libctf: support encodings for enums 2021-03-18 12:40:41 +00:00
slice.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
super-sub-cycles.c
super-sub-cycles.d binutils, ld: make objdump --ctf's parameter optional 2021-10-25 11:17:03 +01:00
typedef-int.c
typedef-long.c
union-1.c