GFortran's scanner appears to go into an infinite loop if you try to pass a directory to 'include'. This patch will check for a directory using stat() after fopen() has verified its existence.

I'm assuming stat() will be OK to call here since add_path_to_list uses it. I've only been able to check it on a Linux system so far.

Botstrapped and tested for regressions on x86_64-pc-linux-gnu. There is a test case for the bug included.

My office is about to close for the Christmas holiday, so I apologise if I don't respond to questions promptly.

2015-12-24  Jim MacArthur <jim.macart...@codethink.co.uk>

        PR fortran/69043
        * scanner.c (load_file): Abort and show an error if stat() shows
        the path is a directory.

Index: gcc/fortran/scanner.c
===================================================================
--- gcc/fortran/scanner.c       (revision 231945)
+++ gcc/fortran/scanner.c       (working copy)
@@ -2200,6 +2200,8 @@ load_file (const char *realfilename, const char *d
   FILE *input;
   int len, line_len;
   bool first_line;
+  struct stat st;
+  int stat_result;
   const char *filename;
   /* If realfilename and displayedname are different and non-null then
      surely realfilename is the preprocessed form of
@@ -2242,6 +2244,16 @@ load_file (const char *realfilename, const char *d
                   current_file->filename, current_file->line, filename);
          return false;
        }
+
+      stat_result = stat (realfilename, &st);
+      if (stat_result == 0 && st.st_mode & S_IFDIR)
+       {
+         fprintf (stderr, "%s:%d: Error: Included path '%s'"
+                  " is a directory.\n",
+                  current_file->filename, current_file->line, filename);
+         fclose (input);
+         return false;
+       }
     }
 
   /* Load the file.

Reply via email to