The C standard Standard identifies specific strings to use for the mode
on calls to fopen()
[ISO/IEC 9899:2011]. To be strictly conforming and portable, one of the strings from the following table (adapted from the C standardStandard) must be used:
Strings to use Use for the mode on calls Calls to fopen()
| Result |
---|---|
| open Open text file for reading |
| truncate Truncate to zero length or create text file for writing |
| appendAppend; open or create text file for writing at end-of-file |
| open Open binary file for reading |
| truncate Truncate to zero length or create binary file for writing |
| appendAppend; open or create binary file for writing at end-of-file |
| open Open text file for update (reading and writing) |
| truncate Truncate to zero length or create text file for update |
| appendAppend; open or create text file for update, writing at end-of-file |
| open Open binary file for update (reading and writing) |
| truncate Truncate to zero length or create binary file for update |
| appendAppend; open or create binary file for update, writing at end-of-file |
If the mode
string begins with one of these sequences, the implementation might choose to ignore the remaining characters, or it might use them to select different kinds of files.
An implementation may define additional mode
strings, but only the modes shown in the table are fully portable and C compliant [ISO/IEC 9899:2011].
Risk Assessment
Using a mode
string that is not recognized by an implementation may cause the call to fopen()
to fail.
...
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Related Guidelines
...
...
ISO/IEC 9899:2011 Section 7.21.15.3, "The fopen
function"
...
...