Versions Compared

Key

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

...

Because the file log is opened twice (once in main() and again in do_stuff()), this program has implementation-defined behavior.

Compliant Solution

In this compliant solution, a reference to the file pointer is passed as an argument to functions that need to perform operations on that file. This reference eliminates the need to open the same file multiple times.

...

Simultaneously opening a file multiple times can result in unexpected errors and nonportable behavior.

Rule

Severity

Likelihood

Remediation Cost

Detectable

Repairable

Priority

Level

FIO31

FIO24-C

Medium

Probable

No

High

No

P4

L3

Automated Detection

Tool

Version

Checker

Description

CodeSonar
Include Page
CodeSonar_V
CodeSonar_V

IO.RACE
(customization)

IO.BRAW

File

System Race Condition

system race condition
Users can implement a custom check that triggers a warning if a file-opening function is called on a file that is already open

.

File Open for Both Read and Write

LDRA tool suite
Include Page
LDRA_V
LDRA_V

75 D

Fully implemented

Related Vulnerabilities

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

Related Guidelines

Partially implemented

Parasoft C/C++test

Include Page
Parasoft_V
Parasoft_V

CERT_C-FIO24-aAvoid race conditions while accessing files

Polyspace Bug Finder

Include Page
Polyspace Bug Finder_V
Polyspace Bug Finder_V

CERT C: Rec. FIO24-CChecks for situations where previously opened resources are reopened (rec. fully covered)

Related Guidelines

 Bibliography

[ISO/IEC 9899:2011Subclause 7.21.3, "Files"

 


...

Image Modified Image Modified Image Modified