-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathputenv-stack-var.yaml
41 lines (41 loc) · 1.33 KB
/
putenv-stack-var.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
rules:
- id: raptor-putenv-stack-var
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
references:
- https://cwe.mitre.org/data/definitions/686
- https://cwe.mitre.org/data/definitions/562
- https://www.sei.cmu.edu/downloads/sei-cert-c-coding-standard-2016-v01.pdf
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: >-
The software calls putenv() with a variable that has a short lifetime,
such as a pointer to an automatic variable allocated on the stack. The
correct behavior is to call putenv() with a static/global string.
severity: INFO
languages:
- c
- cpp
patterns:
- pattern: putenv($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;
...