I plan to commit the attached patch and test case under simple and obvious tomorrow.
Regression tested on x86-64-linux. Regards, Jerry 2016-03-13 Jerry DeLisle <jvdeli...@gcc.gnu.org> Jim MacArthur <jim.macart...@codethink.co.uk> PR fortran/69043 * scanner.c (load_file): Check that included file is not a directory.
diff --git a/gcc/fortran/scanner.c b/gcc/fortran/scanner.c index c4e7974..d4c14bc 100644 --- a/gcc/fortran/scanner.c +++ b/gcc/fortran/scanner.c @@ -2200,6 +2200,8 @@ load_file (const char *realfilename, const char *displayedname, bool initial) 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 @@ -2227,6 +2229,7 @@ load_file (const char *realfilename, const char *displayedname, bool initial) } else input = gfc_open_file (realfilename); + if (input == NULL) { gfc_error_now ("Can't open file %qs", filename); @@ -2242,6 +2245,16 @@ load_file (const char *realfilename, const char *displayedname, bool initial) 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.
! { dg-do compile } ! PR69043 Trying to include a directory causes an infinite loop include '.' program main end program ! { dg-error "is a directory" " " { target *-*-* } 3 }