You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 39 Next »

The C Standard identifies specific strings to use for the mode on calls to fopen(). To be strictly conforming and portable, one of the strings from the following table (adapted from the C Standard) must be used:

Strings to Use for the mode on Calls to fopen()

mode String

Result

r

Open text file for reading

w

Truncate to zero length or 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

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

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

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.

An implementation may define additional mode strings, but only the modes shown in the table are fully portable and C compliant.

Risk Assessment

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

9.7.1

590 S

Partially implemented

Related Vulnerabilities

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

Related Guidelines


  • No labels