Inappropriate I/O operation on device files
Operation can result in security vulnerabilities or a system failure
Description
This defect occurs when you do not check whether a file name parameter refers to a device file before you pass it to these functions:
- fopen()
- fopen_s()
- freopen()
- remove()
- rename()
- CreateFile()
- CreateFileA()
- CreateFileW()
- _wfopen()
- _wfopen_s()
Device files are files in a file system that provide an interface to device drivers. You can use these files to interact with devices.
Inappropriate I/O operation on device files does not raise a defect when:
- You use - stator- lstat-family functions to check the file name parameter before calling the previously listed functions.
- You use a string comparison function to compare the file name against a list of device file names. 
Risk
Operations appropriate only for regular files but performed on device files can result in denial-of-service attacks, other security vulnerabilities, or system failures.
Fix
Before you perform an I/O operation on a file:
- Use - stat(),- lstat(), or an equivalent function to check whether the file name parameter refers to a regular file.
- Use a string comparison function to compare the file name against a list of device file names. 
Examples
Result Information
| Group: Security | 
| Language: C | C++ | 
| Default: Off | 
| Command-Line Syntax: INAPPROPRIATE_IO_ON_DEVICE | 
| Impact: Medium | 
Version History
Introduced in R2018b
See Also
File access between time of check and use
        (TOCTOU) | Opening previously opened resource | Resource leak | Returned value of a sensitive function not
        checked | Vulnerable path manipulation | Find defects (-checkers)
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)