]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
ld: fix segfault when linker script is not found
authorMatthieu Longo <matthieu.longo@arm.com>
Thu, 4 Sep 2025 14:25:21 +0000 (15:25 +0100)
committerMatthieu Longo <matthieu.longo@arm.com>
Wed, 10 Sep 2025 13:03:35 +0000 (14:03 +0100)
commitf04c774b7d49912cc9dcb0cd613e819edb21c3a2
tree2d9e545c9b805abdec2a8703001b8f5a6947c225
parent45f3ea0bbb5e19175009aa513612ae2e8e414f43
ld: fix segfault when linker script is not found

ld previously crashed with a segmentation fault if the specified linker
script could not be found. The issue seems to have been introduced
recently by d048eee2910 [1].

This patch adds a check to ensure that a filename was found after
searching the possible prefixes. If no filename was found, the function
returns NULL, and ldfile_open_command_file_1() emits a proper fatal
error message.
This change prevents the crash and provides a clear diagnostic.

A new generic test was also added to cover this error case.

[1]: https://inbox.sourceware.org/binutils/20250812143757.3565482-1-hjl
     .tools@gmail.com/
ld/ldfile.c
ld/testsuite/ld-scripts/linker-script-not-found.d [new file with mode: 0644]
ld/testsuite/ld-scripts/script.exp