Skip to content

Instantly share code, notes, and snippets.

@abhisek
Created May 2, 2020 05:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhisek/53c3455f9e9fef5bd0a26fed689a69a4 to your computer and use it in GitHub Desktop.
Save abhisek/53c3455f9e9fef5bd0a26fed689a69a4 to your computer and use it in GitHub Desktop.
CodeQL query to find integer casting issues
import go
import semmle.go.dataflow.DataFlow
import semmle.go.dataflow.TaintTracking
class IntegerSource extends Function {
IntegerSource() {
this.hasQualifiedName("strconv", "Atoi") or
this.hasQualifiedName("strconv", "ParseInt")
}
}
class IntegerDownCastingConfig extends TaintTracking::Configuration {
IntegerDownCastingConfig() { this = "IntegerDownCastingConfig" }
override predicate isSource(DataFlow::Node source) {
exists(IntegerSource f |
source.asExpr() = f.getACall().asExpr()
)
}
override predicate isSink(DataFlow::Node sink) {
exists(ConversionExpr expr |
// expr.mayHaveSideEffects() and
expr.getOperand() = sink.asExpr()
)
}
}
from IntegerDownCastingConfig cfg, DataFlow::PathNode source, DataFlow::PathNode sink
where cfg.hasFlowPath(source, sink)
select sink, source, sink
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment