Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Strings to Use for the Mode on Calls to fopen() and fopen_s()

mode String

Result

r

Open text file for reading

w

Truncate to zero length or create text file for writing

wx

Create text file for writing

a

Append; open or create text file for writing at end-of-file

rb

Open binary file for reading

wb

Truncate to zero length or create binary file for writing

wbx

Create binary file for writing

ab

Append; open or create binary file for writing at end-of-file

r+

Open text file for update (reading and writing)

w+

Truncate to zero length or create text file for update

w+x

Create text file for update

a+

Append; open or create text file for update, writing at end-of-file

r+b or rb+

Open binary file for update (reading and writing)

w+b or wb+

Truncate to zero length or create binary file for update

w+bx or wb+x

Create binary file for update

a+b or ab+

Append; 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.

...

Using a mode string that is not recognized by an implementation may cause the call to fopen() to fail.

Recommendation

Severity

Likelihood

Remediation Cost

Priority

Level

FIO11-C

Medium

Probable

Medium

P8

L2

Automated Detection

Tool

Version

Checker

Description

Compass/ROSE

 

 

 




LDRA tool suite
Include Page
LDRA_V
LDRA_V

590 S

Partially implemented

Polyspace Bug Finder

Include Page
Polyspace Bug Finder

R2016a

_V
Polyspace Bug Finder_V

Bad file access mode or status

Access mode argument of function in fopen or open group is invalid

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

Related Guidelines

Bibliography

[ISO/IEC 9899:2011]Subclause 7.21.5.3, "The fopen Function"

...


...