GeneralPurpose-InvalidArgumentInCall¶
The validity of values passed to library functions shall be checked
Required inputs: IR, StaticSemanticAnalysis
Invalid variable in call
This check detects calls to (library) functions where an argument is passed in that the library function cannot handle. The library functions to be checked must be configured (along with the parameter to check and the allowed or disallowed values). Examples are numeric values out of range, null pointers or a local variable causing a use after free.
Bad code (passing a local variable to pthread_once)
void f() {
...
}
void do_once() {
pthread_once_t pred = {0x30B1BCBA, {0}};
pthread_once(&pred, f);
}
Bad code (call realloc with null pointer or negative size)
void change_size(void *p) {
if (!p) {
p = realloc(p, 42);
} else {
p = realloc(p, -1);
}
}Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
argument_violation |
Argument not within allowed values |
None |
False |
local_variable_as_argument |
Argument may not be a local variable. |
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:
{ 'First argument of "calloc" may not be negative': { 'Allowed': '[0.0-DBL_MAX]', 'Functions': 'calloc', 'Parameter': '0' }, 'First argument of "malloc" may not be negative': { 'Allowed': '[0.0-DBL_MAX]', 'Functions': 'malloc', 'Parameter': '0' }, 'Second argument of "calloc" may not be negative': { 'Allowed': '[0.0-DBL_MAX]', 'Functions': 'calloc', 'Parameter': '1' }, 'Second argument of "realloc" may not be negative': { 'Allowed': '[0.0-DBL_MAX]', 'Functions': 'realloc', 'Parameter': '1' } }
no_local_arguments¶
no_local_arguments
Map of function names and argument position that may not be a local variable.Type: dict[bauhaus.analysis.config.QualifiedName, int]
Default:
{ 'pthread_once': 0 }
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.