From 284beb431f44cf0b4b1567ebf9dfe44a24ccfe2e Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Tue, 9 Feb 2021 14:22:23 +0000 Subject: [PATCH] Add a sanity check of files include by .incbin. PR 27381 * read.c (s_incbin): Check that the file to be included is a regular, non-directory file. * testsuite/gas/all/pr27381.s: New test source file. * testsuite/gas/all/pr27381.d: New test control file. * testsuite/gas/all/pr27381.err: Expected error output for the new test. * testsuite/gas/all/gas.exp: Run the new test. --- gas/ChangeLog | 10 ++++++++++ gas/read.c | 9 +++++++++ gas/testsuite/gas/all/gas.exp | 1 + gas/testsuite/gas/all/pr27381.d | 4 ++++ gas/testsuite/gas/all/pr27381.err | 2 ++ gas/testsuite/gas/all/pr27381.s | 1 + 6 files changed, 27 insertions(+) create mode 100644 gas/testsuite/gas/all/pr27381.d create mode 100644 gas/testsuite/gas/all/pr27381.err create mode 100644 gas/testsuite/gas/all/pr27381.s diff --git a/gas/ChangeLog b/gas/ChangeLog index 031bb54d7d2..2c7e533af49 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,13 @@ +2021-02-09 Nick Clifton + + PR 27381 + * read.c (s_incbin): Check that the file to be included is a + regular, non-directory file. + * testsuite/gas/all/pr27381.s: New test source file. + * testsuite/gas/all/pr27381.d: New test control file. + * testsuite/gas/all/pr27381.err: Expected error output for the new test. + * testsuite/gas/all/gas.exp: Run the new test. + 2021-02-09 Alan Modra * Makefile.am (TARG_ENV_HFILES): Remove config/te-symbian.h. diff --git a/gas/read.c b/gas/read.c index 06ca7fbb95f..ede811b0a03 100644 --- a/gas/read.c +++ b/gas/read.c @@ -5909,7 +5909,16 @@ s_incbin (int x ATTRIBUTE_UNUSED) if (binfile) { long file_len; + struct stat filestat; + if (fstat (fileno (binfile), &filestat) != 0 + || ! S_ISREG (filestat.st_mode) + || S_ISDIR (filestat.st_mode)) + { + as_bad (_("unable to include `%s'"), path); + goto done; + } + register_dependency (path); /* Compute the length of the file. */ diff --git a/gas/testsuite/gas/all/gas.exp b/gas/testsuite/gas/all/gas.exp index af36b095e85..6a8491f821f 100644 --- a/gas/testsuite/gas/all/gas.exp +++ b/gas/testsuite/gas/all/gas.exp @@ -470,3 +470,4 @@ gas_test "pr23938.s" "" "" ".xstabs" run_dump_test "nop" run_dump_test "asciz" run_dump_test "pr27384" +run_dump_test "pr27381" diff --git a/gas/testsuite/gas/all/pr27381.d b/gas/testsuite/gas/all/pr27381.d new file mode 100644 index 00000000000..13bc4d047e7 --- /dev/null +++ b/gas/testsuite/gas/all/pr27381.d @@ -0,0 +1,4 @@ +#as: +#error_output: pr27381.err +# The TI targets do not support the .incbin directuve. +#notarget: tic*-*-* diff --git a/gas/testsuite/gas/all/pr27381.err b/gas/testsuite/gas/all/pr27381.err new file mode 100644 index 00000000000..f414210c798 --- /dev/null +++ b/gas/testsuite/gas/all/pr27381.err @@ -0,0 +1,2 @@ +.*pr27381.s: Assembler messages: +.*pr27381.s:1: Error: unable to include `/etc/' diff --git a/gas/testsuite/gas/all/pr27381.s b/gas/testsuite/gas/all/pr27381.s new file mode 100644 index 00000000000..b75523fc6d0 --- /dev/null +++ b/gas/testsuite/gas/all/pr27381.s @@ -0,0 +1 @@ +.incbin "/etc/" -- 2.30.2