CWE-687¶
Function Call With Incorrectly Specified Argument Value. [Improper-Adherence-To-Coding-Standards]
Required inputs: IR, StaticSemanticAnalysis
Demonstrative Examples
Example 1
This Perl code intends to record whether a user authenticated successfully or not, and to exit if the user fails to authenticate. However, when it calls ReportAuth(), the third argument is specified as 0 instead of 1, so it does not exit.
Example Language:Perl (Unsupported language for documentation only)
sub ReportAuth {
my ($username, $result, $fatal) = @_;
PrintLog("auth: username=%s, result=%d", $username, $result);
if (($result ne "success") && $fatal) {
die "Failed!\n";
}
}
sub PrivilegedFunc
{
my $result = CheckAuth($username);
ReportAuth($username, $result, 0);
DoReallyImportantStuff();
}Excerpts from CWE [https://cwe.mitre.org], Copyright (C) 2006-2026, the MITRE Corporation. See 9.4 3rd-Party Licenses in the documentation for full details.Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
argument_violation |
Argument not within allowed values |
None |
False |
incompatible_arg |
Argument {} of call to ‘{}’ should fit into integer range {} to {}. |
None |
False |
invalid_literal_passed |
Argument not within allowed values |
None |
False |
overlapping_copy |
Source and destination of the copy overlap |
None |
False |
possible_argument_violation |
Argument possibly not within allowed values |
None |
False |
Options¶
This rule shares the following common options: confidence, exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
argument_checks¶
argument_checks
Used when StaticSemanticAnalysis is used as analysis engine. Configuration of (dis)allowed values. This is a dict key -> dict with keys 'Functions', 'Parameter', and 'Allowed'/'Disallowed'. The parameter number counting starts at 0. Arguments passed in for this parameters are checked against the value specification given with '(Dis)allowed'.Type: dict[str, dict[str, str]]
Default:
{ 'Absolute value of most negative number cannot be represented': { 'Disallowed': 'INT_MIN', 'Functions': 'abs', 'Parameter': '0' }, 'Argument should be a lowercase letter': { 'Allowed': '[a-z]', 'Functions': 'toupper', 'Parameter': '0' }, 'Argument should be an unsigned character': { 'Allowed': '0-255', 'Functions': 'iscntrl,isblank,isspace,isupper,islower,isalpha,isdigit,isxdigit,isalnum,ispunct,isgraph,isprint', 'Parameter': '0' }, 'Argument should be an uppercase letter': { 'Allowed': '[A-Z]', 'Functions': 'tolower', 'Parameter': '0' }, 'Negative numbers must not be passed to this function': { 'Allowed': '[0.0-DBL_MAX]', 'Functions': 'sqrt,log', 'Parameter': '0' }, 'Second parameter should not be zero': { 'Disallowed': '0.0', 'Functions': '__math::fmod,fmod,fmodf', 'Parameter': '1' } }
functions¶
functions : set[bauhaus.analysis.config.QualifiedName] = {'__builtin___memcpy_chk', 'memcpy'}
precondition_checks¶
precondition_checks : set[bauhaus.analysis.config.FunctionName] = {'__builtin___strcpy_chk', 'calloc', 'malloc', 'realloc', 'strcpy'}
pre_conditions option of rules in
Analysis/AnalysisControl/Environment/Externals.
To create a new rule, copy Externals-FunctionSummary
and adjust the functions
option to match a set of functions to which the preconditions should apply.
Then set pre_conditions
according to the required preconditions, e.g., @param0 > 0 or
@param0 == 0 || @param0 == 1.
routines_and_limits¶
routines_and_limits
Names of routines relevant to this check, together with the (zero based) parameter index and the expected value range (min, max). Can use None if upper or lower limit is not needed.Type: dict[bauhaus.analysis.config.QualifiedName, dict[int, typing.Tuple[int, int]]]
Default:
{ 'memset': { 1: (0, 255) } }