Fortran: Fixes invalid read with 'use, only:'
Corrects an invalid read in the Fortran compiler's module loading when using 'use, only:' with names prefixed by '__'.
This commit fixes an invalid read vulnerability in the Fortran compiler’s module loading mechanism. The issue occurred when processing use, only: statements with module names prefixed by double underscores (‘__’). The compiler’s load_needed function would incorrectly attempt to scan an empty name in such cases, leading to an invalid read. The fix prevents this scanning of empty names, ensuring the compiler handles these constructs safely.
In Details
The Fortran module loading logic in module.cc (specifically the load_needed function) had an issue where it would scan an empty name when processing use, only: statements involving module names prefixed with __. This could lead to an invalid read. The commit adds a check to prevent scanning of an empty name when the prefix is __.
- use, only:
- A Fortran statement that allows a program to selectively import specific entities (procedures, variables, etc.) from a module, rather than importing all available entities.
- module
- A Fortran construct that encapsulates related data and procedures, providing a way to organize code and manage scopes. Modules can be used to share definitions between different program units.
- invalid read
- A memory access error where the program attempts to read from a memory address that has not been allocated or is otherwise inaccessible, potentially leading to crashes or security vulnerabilities.