An application programming interface (API) specifies how a function is intended to be called. Calling a function with incorrect arguments can result in unexpected or unintended program behavior. Functions that are appropriately declared (see as in guideline DCL07-C. Include the appropriate type information in function declarators) will typically fail compilation if they are supplied with the wrong number or types of arguments. However, there are cases where supplying the incorrect arguments to a function will at best generate compiler warnings. These warnings should be resolved (see but do not prevent program compilation.(See guideline MSC00-C. Compile cleanly at high warning levels.) but do not prevent program compilation.
Noncompliant Code Example (Function Pointers)
...
Wiki Markup |
---|
The POSIX function {{open()}} \[[Open Group 042004|AA. Bibliography#Open Group 04]\] is a variadic function with the following prototype: |
...
The open()
function accepts a third argument to determine a newly created file's access mode. If open()
is used to create a new file and the third argument is omitted, the file may be created with unintended access permissions. (see See guideline FIO06-C. Create files with appropriate access permissions.).
In this noncompliant code example from a vulnerability in the useradd()
function of the shadow-utils
package CVE-2006-1174 , the third argument to open()
has been accidentally omitted.
...
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
EXP37-C | medium | probable | high | P4 | L3 |
Automated Detection
Tool | Version | Checker | Description |
---|
...
|
|
|
| ||||||||||
|
|
|
|
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Other Languages
Related Guidelines
This rule appears in the C++ Secure Coding Standard as : EXP37-CPP. Call variadic functions with the arguments intended by the API.
Bibliography
Wiki Markup |
---|
\[[CVE|AA. Bibliography#CVE]\] [CVE-2006-1174 | http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-1174] \[[ISO/IEC 9899:1999|AA. Bibliography#ISO/IEC 9899-1999]\] Forward and Section 6.9.1, "Function definitions" \[[ISO/IEC PDTR 24772|AA. Bibliography#ISO/IEC PDTR 24772]\] "OTR Subprogram Signature Mismatch" \[[MISRA 042004|AA. Bibliography#MISRA 04]\] Rule 16.6 \[[MITRE 072007|AA. Bibliography#MITRE 07]\] [CWE ID 628|http://cwe.mitre.org/data/definitions/628.html], "Function Call with Incorrectly Specified Arguments" \[[Spinellis 062006|AA. Bibliography#Spinellis 06]\] Section 2.6.1, "Incorrect Routine or Arguments" |
...