Skip to content

Commit 602bb40

Browse files
authored
Merge pull request #13949 from owen-mc/go/change-flowstate-for-incorrect-integer-conversion
Go: Improve incorrect integer conversion
2 parents 333e607 + 11b9260 commit 602bb40

11 files changed

+407
-136
lines changed

go/ql/lib/semmle/go/frameworks/Stdlib.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ module IntegerParser {
117117
* input is 0 then it means the bit size of `int` and `uint`.
118118
*/
119119
FunctionInput getTargetBitSizeInput() { none() }
120+
121+
/** Gets whether the function is for parsing signed or unsigned integers. */
122+
boolean isSigned() { none() }
120123
}
121124
}
122125

go/ql/lib/semmle/go/frameworks/stdlib/Strconv.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,26 @@ module Strconv {
1111
Atoi() { this.hasQualifiedName("strconv", "Atoi") }
1212

1313
override int getTargetBitSize() { result = 0 }
14+
15+
override boolean isSigned() { result = true }
1416
}
1517

1618
/** The `ParseInt` function. */
1719
class ParseInt extends IntegerParser::Range {
1820
ParseInt() { this.hasQualifiedName("strconv", "ParseInt") }
1921

2022
override FunctionInput getTargetBitSizeInput() { result.isParameter(2) }
23+
24+
override boolean isSigned() { result = true }
2125
}
2226

2327
/** The `ParseUint` function. */
2428
class ParseUint extends IntegerParser::Range {
2529
ParseUint() { this.hasQualifiedName("strconv", "ParseUint") }
2630

2731
override FunctionInput getTargetBitSizeInput() { result.isParameter(2) }
32+
33+
override boolean isSigned() { result = false }
2834
}
2935

3036
/**

0 commit comments

Comments
 (0)