Add a sanity check of files include by .incbin.
authorNick Clifton <nickc@redhat.com>
Tue, 9 Feb 2021 14:22:23 +0000 (14:22 +0000)
committerNick Clifton <nickc@redhat.com>
Tue, 9 Feb 2021 14:22:23 +0000 (14:22 +0000)
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
gas/read.c
gas/testsuite/gas/all/gas.exp
gas/testsuite/gas/all/pr27381.d [new file with mode: 0644]
gas/testsuite/gas/all/pr27381.err [new file with mode: 0644]
gas/testsuite/gas/all/pr27381.s [new file with mode: 0644]

index 031bb54d7d2fa02c4d5e1c8558b71e8bd6ce7188..2c7e533af49ab2f230985d5a67598ddade495d58 100644 (file)
@@ -1,3 +1,13 @@
+2021-02-09  Nick Clifton  <nickc@redhat.com>
+
+       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  <amodra@gmail.com>
 
        * Makefile.am (TARG_ENV_HFILES): Remove config/te-symbian.h.
index 06ca7fbb95f7b567df875279bc642558ef22a268..ede811b0a0337c6f3199dc89d825824f2cafcf3b 100644 (file)
@@ -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.  */
index af36b095e85d17d4ade7d6258737cffe46ef61b1..6a8491f821f265faa8c27befd2ce0deadd4422a2 100644 (file)
@@ -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 (file)
index 0000000..13bc4d0
--- /dev/null
@@ -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 (file)
index 0000000..f414210
--- /dev/null
@@ -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 (file)
index 0000000..b75523f
--- /dev/null
@@ -0,0 +1 @@
+.incbin "/etc/"