-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathincorrect-unsigned-comparison.yaml
40 lines (40 loc) · 1.49 KB
/
incorrect-unsigned-comparison.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
rules:
- id: raptor-incorrect-unsigned-comparison
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
references:
- https://cwe.mitre.org/data/definitions/697
- https://g.co/kgs/PCHQjJ
confidence: HIGH
# NOTE: some types are not covered.
# NOTE: incorrect unsigned assigments are not covered.
message: >-
Checking if an unsigned variable is negative makes no sense and is
usually a good indication that something is probably wrong with the
code.
severity: WARNING
languages:
- c
- cpp
pattern-either:
# < (always false)
- pattern: (unsigned short $UNSIGNED) < 0
- pattern: (unsigned short int $UNSIGNED) < 0
- pattern: (unsigned int $UNSIGNED) < 0
- pattern: (unsigned long $UNSIGNED) < 0
- pattern: (unsigned long int $UNSIGNED) < 0
- pattern: (size_t $UNSIGNED) < 0
# <=
- pattern: (unsigned short $UNSIGNED) <= 0
- pattern: (unsigned short int $UNSIGNED) <= 0
- pattern: (unsigned int $UNSIGNED) <= 0
- pattern: (unsigned long $UNSIGNED) <= 0
- pattern: (unsigned long int $UNSIGNED) <= 0
- pattern: (size_t $UNSIGNED) <= 0
# >= (always true)
- pattern: (unsigned short $UNSIGNED) >= 0
- pattern: (unsigned short int $UNSIGNED) >= 0
- pattern: (unsigned int $UNSIGNED) >= 0
- pattern: (unsigned long $UNSIGNED) >= 0
- pattern: (unsigned long int $UNSIGNED) >= 0
- pattern: (size_t $UNSIGNED) >= 0