From: Mathias Aparicio Date: Thu, 9 Apr 2026 09:55:37 +0000 (+0200) Subject: ada: Fix directories being identified as executables on Windows X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1b4e77b4ffd64273bfd280f61135901714ca28e4;p=thirdparty%2Fgcc.git ada: Fix directories being identified as executables on Windows 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. --- diff --git a/gcc/ada/adaint.c b/gcc/ada/adaint.c index db871d1e102..a63408370f7 100644 --- a/gcc/ada/adaint.c +++ b/gcc/ada/adaint.c @@ -2176,6 +2176,13 @@ __gnat_is_executable_file_attr (char* name, struct file_attributes* attr) 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; @@ -2198,9 +2205,7 @@ __gnat_is_executable_file_attr (char* name, struct file_attributes* attr) 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);