aboutsummaryrefslogtreecommitdiff
path: root/gas/read.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2021-02-09 14:22:23 +0000
committerNick Clifton <nickc@redhat.com>2021-02-09 14:22:23 +0000
commit284beb431f44cf0b4b1567ebf9dfe44a24ccfe2e (patch)
treea1dfa0a789a75941c4c37cde324e779b37b5828e /gas/read.c
parent9b87f84a3513c852eca395e3aa47081ef2f12e60 (diff)
downloadfsf-binutils-gdb-284beb431f44cf0b4b1567ebf9dfe44a24ccfe2e.zip
fsf-binutils-gdb-284beb431f44cf0b4b1567ebf9dfe44a24ccfe2e.tar.gz
fsf-binutils-gdb-284beb431f44cf0b4b1567ebf9dfe44a24ccfe2e.tar.bz2
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.
Diffstat (limited to 'gas/read.c')
-rw-r--r--gas/read.c9
1 files changed, 9 insertions, 0 deletions
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. */