Avoid possible symlinks in C++ when using ofstream

498 Views Asked by At

I have this code

    ofstream file;
    file.open(filePath, std::ios::app);    
    file << content;
    file.close();

When I run Flawfinder it says:

[2] (misc) open:
  Check when opening files - can an attacker redirect it (via symlinks),
  force the opening of special file type (e.g., device files), move things
  around to create a race condition, control its ancestors, or change its
  contents? (CWE-362).

My question: is there any better/safer way to write the same code above to deal with files in order to avoid such possible security vulnerabilities?

0

There are 0 best solutions below