-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathret-stack-address.yaml
65 lines (65 loc) · 2.02 KB
/
ret-stack-address.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
rules:
- id: raptor-ret-stack-address
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
references:
- https://cwe.mitre.org/data/definitions/562
- https://github.com/struct/mms
- https://www.sei.cmu.edu/downloads/sei-cert-c-coding-standard-2016-v01.pdf
- https://docs.microsoft.com/en-us/cpp/sanitizers/asan-error-examples
- https://rules.sonarsource.com/c/type/Bug/RSPEC-946
confidence: LOW
# NOTE: static variables matching apparently is not supported by Semgrep.
# NOTE: multiple pointer assignments and other ways to persist after
# function returns (e.g., output parameter) are not covered.
message: >-
A function returns the address of a stack variable, which will cause
unintended program behavior, typically in the form of a crash.
severity: INFO
languages:
- c
- cpp
pattern-either:
- patterns:
- pattern: return $PTR;
- pattern-either:
# array
- pattern-inside: |
$TYPE $PTR[$LEN];
...
- pattern-inside: |
$TYPE $PTR[$LEN] = $EXPR;
...
# pointer to array
- pattern-inside: |
$TYPE $ARR[$LEN];
...
$PTR = $ARR;
...
- pattern-inside: |
$TYPE $ARR[$LEN] = $EXPR;
...
$PTR = $ARR;
...
- patterns:
# address of local variable
- pattern: return &$VAR;
- pattern-either:
- pattern-inside: |
$TYPE $VAR;
...
- pattern-inside: |
$TYPE $VAR = $EXPR;
...
- pattern-inside: |
$TYPE $VAR[$LEN];
...
- pattern-inside: |
$TYPE $VAR[$LEN] = $EXPR;
...
- pattern-inside: |
$TYPE * $VAR;
...
- pattern-inside: |
$TYPE * $VAR = $EXPR;
...