-
Notifications
You must be signed in to change notification settings - Fork 32
/
string-to-int-signedness-cast.yaml
132 lines (113 loc) · 3.37 KB
/
string-to-int-signedness-cast.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
rules:
- id: string-to-int-signedness-cast
message: Downcasting or changing sign of an integer with `$CAST_METHOD` method
languages: [go]
severity: WARNING
metadata:
category: security
cwe: "CWE-681: Incorrect Conversion between Numeric Types"
subcategory: [audit]
confidence: HIGH
likelihood: LOW
impact: MEDIUM
technology: [--no-technology--]
description: "Integer underflows"
references:
- https://github.com/golang/go/issues/30209
pattern-either:
# 64 -> lower or sign
- patterns:
- metavariable-pattern:
metavariable: $CAST_METHOD
pattern-either:
- pattern: uint8
- pattern: uint16
- pattern: uint32
- pattern: int8
- pattern: int16
- pattern: int32
- pattern-either:
- pattern: |
$X, ... = strconv.Atoi(...)
...
$CAST_METHOD($X)
- pattern: |
$X, ... = strconv.ParseInt(..., ..., 64)
...
$CAST_METHOD($X)
- pattern: |
$X, ... = strconv.ParseUint(..., ..., 64)
...
$CAST_METHOD($X)
# assume int has 64 bits
- pattern: |
$X, ... = strconv.Atoi(...)
...
uint64($X)
- pattern: |
$X, ... = strconv.ParseInt(..., ..., 64)
...
uint64($X)
- pattern: |
$X, ... = strconv.ParseUint(..., ..., 64)
...
int64($X)
# 32 -> lower or sign
- patterns:
- metavariable-pattern:
metavariable: $CAST_METHOD
pattern-either:
- pattern: uint8
- pattern: uint16
- pattern: int8
- pattern: int16
- pattern-either:
- pattern: |
$X, ... = strconv.ParseInt(..., ..., 32)
...
$CAST_METHOD($X)
- pattern: |
$X, ... = strconv.ParseUint(..., ..., 32)
...
$CAST_METHOD($X)
- pattern: |
$X, ... = strconv.ParseInt(..., ..., 32)
...
uint32($X)
- pattern: |
$X, ... = strconv.ParseUint(..., ..., 32)
...
int32($X)
# 16 -> lower or sign
- patterns:
- metavariable-pattern:
metavariable: $CAST_METHOD
pattern-either:
- pattern: uint8
- pattern: int8
- pattern-either:
- pattern: |
$X, ... = strconv.ParseInt(..., ..., 16)
...
$CAST_METHOD($X)
- pattern: |
$X, ... = strconv.ParseUint(..., ..., 16)
...
$CAST_METHOD($X)
- pattern: |
$X, ... = strconv.ParseInt(..., ..., 16)
...
uint16($X)
- pattern: |
$X, ... = strconv.ParseUint(..., ..., 16)
...
int16($X)
# 8 -> sign
- pattern: |
$X, ... = strconv.ParseInt(..., ..., 8)
...
uint8($X)
- pattern: |
$X, ... = strconv.ParseUint(..., ..., 8)
...
int8($X)