...
The gets
function was deprecated by Technical Corrigendum 3.
Obsolescent Functions
The following functions are obsolescent and should be avoided in favor of either the portable equivalent or, if available, the more secure alternatives defined in \[ [ISO/IEC TR 24731-1|AA. Bibliography#ISO/IEC TR 24731-1-2007]\] Extensions to the C Library, --- Part — Part I: Bounds-checking interfaces, and \ [[ISO/IEC TR 24731-2|AA. Bibliography#ISO/IEC TR 24731-2-2010]\] Extensions to the C Library, --- — Part II: Dynamic Allocation Functions. (Several of the "Portable Equivalent" entries are specified in the POSIX standard.) Wiki Markup
Function | Portable Equivalent | Secure Alternative |
---|---|---|
|
| |
| |
|
| |
|
| |
|
| |
|
|
| |
|
| |
| | |
| |
|
|
| |
|
| |
| | |
|
| |
| | |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
|
|
|
|
| |
|
| |
|
|
| |
| | |
|
| |
|
| |
| | |
| | |
|
| |
| | |
| | |
| | |
|
| |
| | |
| |
|
| | |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
| | |
|
| |
| | |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
...
MISRA Rule 20.4
Bibliography
\[[Burch 2006|AA. Bibliography#Burch06]\]
\[[CERT 2006c|AA. Bibliography#CERT 06c]\]
\[[Seacord 2005a|AA. Bibliography#Seacord 05a]\] Chapter 2, [Burch 2006] Wiki Markup
[CERT 2006c]
[Seacord 2005a] Chapter 2, "Strings"
Using deprecated or obsolescent functions shall be diagnosed because there exist equivalent functions that are more secure.
...
Obsolescent | Recommended | Rationale |
---|---|---|
| | Non-reentrant. |
| | No error detection. |
| | No error detection. |
| | No error detection. |
| | No error detection. |
| | Non-reentrant. |
| | No exclusive access to file. |
| | No exclusive access to file. |
| | No error detection. |
| | No error detection. |
...
The {{atof,
atoi,
atol
}}, and {{atoll
}} functions are obsolescent because the {{strod,
strtof,
strtol,
strtold,
strtoll,
strotul
}}, and {{strtoull
}} functions can emulate their usage and have more robust error handling capabilities. See guideline [INT05-C. Do not use input functions to convert character data if they cannot handle all possible inputs|seccode:INT05-C. Do not use input functions to convert character data if they cannot handle all possible inputs] \[[CERT C Secure Coding Standard 2010|Bibliography#CERT C Secure Coding Standard 10]\].
Wiki Markup |
---|
The {{fopen}} and {{freopen}} functions are obsolescent because the {{fopen_s}} and {{freopen_s}} functions can emulate their usage and improve security by protecting the file from unauthorized access by setting its file protection and opening the file with exclusive access \[[ISO/IEC WG14 N1173|Bibliography#ISO/IEC WG14 N1173]\]. |
Wiki Markup |
---|
The {{setbuf}} function is obsolescent because {{setbuf}} does not return a value and can be emulated using {{setvbuf}}. See guideline [FIO12-C. Prefer setvbuf() to setbuf()|seccode:FIO12-C. Prefer setvbuf() to setbuf()] \[[CERT C Secure Coding Standard 2010|Bibliography#CERT C Secure Coding Standard 10]\]. |
Wiki Markup |
---|
The {{rewind}} function is obsolescent because {{rewind}} does not return a value and can be emulated using {{fseek}}. See guideline [FIO07-C. Prefer fseek() to rewind()|seccode:FIO07-C. Prefer fseek() to rewind()] \[[CERT C Secure Coding Standard 2010|Bibliography#CERT C Secure Coding Standard 10]\]. |
inputs [CERT C Secure Coding Standard 2010].
The fopen
and freopen
functions are obsolescent because the fopen_s
and freopen_s
functions can emulate their usage and improve security by protecting the file from unauthorized access by setting its file protection and opening the file with exclusive access [ISO/IEC WG14 N1173].
The setbuf
function is obsolescent because setbuf
does not return a value and can be emulated using setvbuf
. See guideline FIO12-C. Prefer setvbuf() to setbuf() [CERT C Secure Coding Standard 2010].
The rewind
function is obsolescent because rewind
does not return a value and can be emulated using fseek
. See guideline FIO07-C. Prefer fseek() to rewind() [CERT C Secure Coding Standard 2010].
The The asctime
and ctime
functions are obsolescent because they use non-reentrant static buffers and can be emulated using asctime_s
and ctime_s
.
...
MITRE CWE: CWE-73 "External Control of File Name or Path, "CWE-367, "Time-of-check Time-of-use Race Condition," CWE-676, "Use of Potentially Dangerous Function," CWE-192, "Integer Coercion Error," CWE-197, "Numeric Truncation Error," CWE-464, "Addition of Data Structure Sentinel," CWE-676, "Use of Potentially Dangerous Function," and CWE-20, "Insufficient Input Validation"
Bibliography
...
\[[Apple Secure Coding Guide|Bibliography#Apple Secure Coding Guide]\] "Avoiding Race Conditions and Insecure File Operations"
\[[CERT C Secure Coding Standard 2010|Bibliography#CERT C Secure Coding Standard 10]\]"[MSC34-C. Do not use deprecated or obsolescent functions|seccode:MSC34-C. Do not use deprecated or obsolescent functions]", "[FIO01-C. Be careful using functions that use file names for identification|seccode:FIO01-C. Be careful using functions that use file names for identification]", "[FIO07-C. Prefer fseek() to rewind()|seccode:FIO07-C. Prefer fseek() to rewind()]", "[FIO12-C. Prefer setvbuf() to setbuf()|seccode:FIO12-C. Prefer setvbuf() to setbuf()]", "[INT05-C. Do not use input functions to convert character data if they cannot handle all possible inputs|seccode:INT05-C. Do not use input functions to convert character data if they cannot handle all possible inputs]", "[INT06-C. Use strtol() or a related function to convert a string token to an integer|seccode:INT06-C. Use strtol() or a related function to convert a string token to an integer]", "[STR06-C. Do not assume that strtok() leaves the parse string unchanged|seccode:STR06-C. Do not assume that strtok() leaves the parse string unchanged]", "[STR07-C. Use TR 24731 for remediation of existing string manipulation code|STR07-C. Use the bounds-checking interfaces for remediation of existing string manipulation code]"
\[[Drepper 2006|Bibliography#Drepper 06]\] Section 2.2.1 "Identification When Opening"
\[[Klein 2002|Bibliography#Klein 02]\]
\[[Linux 2007|Bibliography#Linux 07]\] {{strtok}}(3)
\[[Open Group 2004|Bibliography#Open Group 04]\] "The {{open}} function"
\[[Seacord 2005a|Bibliography#Seacord 05a]\] Chapter 2, "Strings," and Chapter 7, "File I/O"
\[[Seacord 2005b|Bibliography#Seacord 05b]\Guide] "Avoiding Race Conditions and Insecure File Operations"
[CERT C Secure Coding Standard 2010]"MSC34-C. Do not use deprecated or obsolescent functions", "FIO01-C. Be careful using functions that use file names for identification", "FIO07-C. Prefer fseek() to rewind()", "FIO12-C. Prefer setvbuf() to setbuf()", "INT05-C. Do not use input functions to convert character data if they cannot handle all possible inputs", "INT06-C. Use strtol() or a related function to convert a string token to an integer", "STR06-C. Do not assume that strtok() leaves the parse string unchanged", "STR07-C. Use TR 24731 for remediation of existing string manipulation code"
[Drepper 2006] Section 2.2.1 "Identification When Opening"
[Klein 2002]
[Linux 2007] strtok
(3)
[Open Group 2004] "The open
function"
[Seacord 2005a] Chapter 2, "Strings," and Chapter 7, "File I/O"
[Seacord 2005b]
...
49. Miscellaneous (MSC) MSC35-C. Do not include any executable statements inside a switch statement before the first case label