-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathincorrect-use-of-sizeof.yaml
39 lines (39 loc) · 1.36 KB
/
incorrect-use-of-sizeof.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
rules:
- id: raptor-incorrect-use-of-sizeof
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
references:
- https://cwe.mitre.org/data/definitions/467
- https://g.co/kgs/PCHQjJ
- https://github.com/struct/mms
- https://dustri.org/b/playing-with-weggli.html
confidence: MEDIUM
# NOTE: another relevant pattern would be sizeof('...'), but
# unfortunately that's currently not supported by Semgrep.
# NOTE: see also cpp.correctness.sizeof-*.
message: >-
The code calls sizeof() on a malloced pointer type, which always
returns the wordsize/8. This can produce an unexpected result if the
programmer intended to determine how much memory has been allocated.
severity: WARNING
languages:
- c
- cpp
pattern-either:
# type-based patterns (some types are missing)
- patterns:
- pattern: sizeof((char * $PTR))
- pattern-not: sizeof("...")
- pattern: sizeof((int * $PTR))
- pattern: sizeof((float * $PTR))
- pattern: sizeof((double * $PTR))
# other patterns (function calls are not covered)
- patterns:
- pattern: sizeof($PTR)
- pattern-either:
- pattern-inside: |
$TYPE * $PTR;
...
- pattern-inside: |
$TYPE * $PTR = $EXPR;
...