On Windows the `__gnat_is_executable_file_attr` checks if a file
is executable but does not check if it is a regular file or a directory.
This may lead to the execution of a directory which will make the program
crash. This patch fixes the issue by checking if the file is regular
before checking if it is executable.
gcc/ada/ChangeLog:
* adaint.c (__gnat_is_executable_file_attr): Initialize
attr->regular using __gnat_is_regular_file_attr. Directly return
0 before checking if executable if the attr->regular is 0.
Remove the now unnecessary check for invalid_file_attributes.
if (attr->executable == ATTR_UNSET)
{
#if defined (_WIN32)
+ __gnat_is_regular_file_attr (name, attr);
+ if (!attr->regular)
+ {
+ attr->executable = 0;
+ return 0;
+ }
+
TCHAR wname [GNAT_MAX_PATH_LEN + 2];
GENERIC_MAPPING GenericMapping;
while ((l = _tcsstr(last+1, _T(".exe"))))
last = l;
- attr->executable =
- GetFileAttributes (wname) != INVALID_FILE_ATTRIBUTES
- && (last - wname) == (int) (_tcslen (wname) - 4);
+ attr->executable = (last - wname) == (int)(_tcslen (wname) - 4);
}
#else
__gnat_stat_to_attr (-1, name, attr);