From 284beb431f44cf0b4b1567ebf9dfe44a24ccfe2e Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Tue, 9 Feb 2021 14:22:23 +0000 Subject: 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/read.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'gas/read.c') diff --git a/gas/read.c b/gas/read.c index 06ca7fb..ede811b 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. */ -- cgit v1.1