Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 4bfb2b4

Browse files
committed
Address review comments 1
1 parent 681ca90 commit 4bfb2b4

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

ql/src/Security/CWE-681/IncorrectIntegerConversion.qhelp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ the bit size you specified when parsing the number.
2525
</p>
2626
<p>
2727
If this is not possible, then add upper (and lower) bound checks specific to each type and
28-
bit size (you can find the minimum and maximum value for each type in the `math` package).
28+
bit size (you can find the minimum and maximum value for each type in the <code>math</code> package).
2929
</p>
3030
</recommendation>
3131

ql/src/Security/CWE-681/IncorrectIntegerConversion.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class ConversionWithoutBoundsCheckConfig extends TaintTracking::Configuration {
6464

6565
override predicate isSource(DataFlow::Node source) {
6666
exists(ParserCall pc, int bitSize | source = pc.getResult(0) |
67-
sourceIsSigned = pc.getTargetIsSigned() and
67+
(if pc.targetIsSigned() then sourceIsSigned = true else sourceIsSigned = false) and
6868
(if pc.getTargetBitSize() = 0 then bitSize = 0 else bitSize = pc.getTargetBitSize()) and
6969
// `bitSize` could be any value between 0 and 64, but we can round
7070
// it up to the nearest size of an integer type without changing
@@ -74,7 +74,7 @@ class ConversionWithoutBoundsCheckConfig extends TaintTracking::Configuration {
7474
}
7575

7676
/**
77-
* Holds if sink is a typecast to an integer type with size `bitSize` (where
77+
* Holds if `sink` is a typecast to an integer type with size `bitSize` (where
7878
* 0 represents architecture-dependent) and the expression being typecast is
7979
* not also in a right-shift expression.
8080
*/

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -522,18 +522,18 @@ module StrConv {
522522
ParseFloat() { this.hasQualifiedName("strconv", "ParseFloat") }
523523
}
524524

525-
/** A function that parses integers with a specifiable bitSize. */
525+
/** A function that parses integers with a specifiable bit size. */
526526
class ParseInt extends Function {
527527
ParseInt() { this.hasQualifiedName("strconv", "ParseInt") }
528528
}
529529

530-
/** A function that parses unsigned integers with a specifiable bitSize. */
530+
/** A function that parses unsigned integers with a specifiable bit size. */
531531
class ParseUint extends Function {
532532
ParseUint() { this.hasQualifiedName("strconv", "ParseUint") }
533533
}
534534

535535
/**
536-
* A constant that gives the size in bits of an int or uint
536+
* A constant that gives the size in bits of an `int` or `uint`
537537
* value on the current architecture (32 or 64).
538538
*/
539539
class IntSize extends DeclaredConstant {
@@ -549,14 +549,14 @@ module ParserCall {
549549
abstract int getTargetBitSize();
550550

551551
/** Holds if the type of the result number is signed. */
552-
abstract boolean getTargetIsSigned();
552+
abstract predicate targetIsSigned();
553553

554554
/** Gets the name of the parser function. */
555555
abstract string getParserName();
556556
}
557557
}
558558

559-
/** A call to a number-parsing function */
559+
/** A call to a number-parsing function. */
560560
class ParserCall extends DataFlow::CallNode {
561561
ParserCall::Range self;
562562

@@ -566,7 +566,7 @@ class ParserCall extends DataFlow::CallNode {
566566
int getTargetBitSize() { result = self.getTargetBitSize() }
567567

568568
/** Holds if the type of the result number is signed. */
569-
boolean getTargetIsSigned() { result = self.getTargetIsSigned() }
569+
predicate targetIsSigned() { self.targetIsSigned() }
570570

571571
/** Gets the name of the parser function. */
572572
string getParserName() { result = self.getParserName() }
@@ -579,18 +579,18 @@ class ParserCall extends DataFlow::CallNode {
579579
}
580580
}
581581

582-
/** A call to `strconv.Atoi` */
582+
/** A call to `strconv.Atoi`. */
583583
class AtoiCall extends DataFlow::CallNode, ParserCall::Range {
584584
AtoiCall() { exists(StrConv::Atoi atoi | this = atoi.getACall()) }
585585

586586
override int getTargetBitSize() { result = 0 }
587587

588-
override boolean getTargetIsSigned() { result = true }
588+
override predicate targetIsSigned() { any() }
589589

590590
override string getParserName() { result = "strconv.Atoi" }
591591
}
592592

593-
/** A call to `strconv.ParseInt` */
593+
/** A call to `strconv.ParseInt`. */
594594
class ParseIntCall extends DataFlow::CallNode, ParserCall::Range {
595595
ParseIntCall() { exists(StrConv::ParseInt parseInt | this = parseInt.getACall()) }
596596

@@ -600,12 +600,12 @@ class ParseIntCall extends DataFlow::CallNode, ParserCall::Range {
600600
else result = this.getArgument(2).getIntValue()
601601
}
602602

603-
override boolean getTargetIsSigned() { result = true }
603+
override predicate targetIsSigned() { any() }
604604

605605
override string getParserName() { result = "strconv.ParseInt" }
606606
}
607607

608-
/** A call to `strconv.ParseUint` */
608+
/** A call to `strconv.ParseUint`. */
609609
class ParseUintCall extends DataFlow::CallNode, ParserCall::Range {
610610
ParseUintCall() { exists(StrConv::ParseUint parseUint | this = parseUint.getACall()) }
611611

@@ -615,7 +615,7 @@ class ParseUintCall extends DataFlow::CallNode, ParserCall::Range {
615615
else result = this.getArgument(2).getIntValue()
616616
}
617617

618-
override boolean getTargetIsSigned() { result = false }
618+
override predicate targetIsSigned() { none() }
619619

620620
override string getParserName() { result = "strconv.ParseUint" }
621621
}

0 commit comments

Comments
 (0)