mirror of
https://github.com/github/codeql.git
synced 2026-01-29 22:32:58 +01:00
Autoformat all QL.
This commit is contained in:
@@ -12,7 +12,6 @@ import go
|
||||
*/
|
||||
class SuppressionComment extends Locatable {
|
||||
string text;
|
||||
|
||||
string annotation;
|
||||
|
||||
SuppressionComment() {
|
||||
|
||||
@@ -58,9 +58,9 @@ predicate escapes(DataFlow::Node nd) {
|
||||
* the embedded field has the pointer type `*T` or just type `T`.
|
||||
*/
|
||||
Type getEmbeddedType(Type t, boolean isPtr) {
|
||||
exists(Type embedded |
|
||||
t.getUnderlyingType().(StructType).hasOwnField(_, _, embedded, true) |
|
||||
if embedded instanceof PointerType then (
|
||||
exists(Type embedded | t.getUnderlyingType().(StructType).hasOwnField(_, _, embedded, true) |
|
||||
if embedded instanceof PointerType
|
||||
then (
|
||||
result = embedded.(PointerType).getBaseType() and
|
||||
isPtr = true
|
||||
) else (
|
||||
@@ -71,9 +71,7 @@ Type getEmbeddedType(Type t, boolean isPtr) {
|
||||
}
|
||||
|
||||
/** Gets an embedded type of `t`. */
|
||||
Type getEmbeddedType(Type t) {
|
||||
result = getEmbeddedType(t, _)
|
||||
}
|
||||
Type getEmbeddedType(Type t) { result = getEmbeddedType(t, _) }
|
||||
|
||||
/**
|
||||
* Gets a transitive embedded type of `t`, where at least one of the embeddings goes through a
|
||||
|
||||
@@ -26,9 +26,7 @@ predicate inVoidContext(Expr e) {
|
||||
/**
|
||||
* Holds if `ce` is a call to a stub function with an empty body.
|
||||
*/
|
||||
predicate callToStubFunction(CallExpr ce) {
|
||||
ce.getTarget().getBody().getNumStmt() = 0
|
||||
}
|
||||
predicate callToStubFunction(CallExpr ce) { ce.getTarget().getBody().getNumStmt() = 0 }
|
||||
|
||||
from Expr e
|
||||
where
|
||||
|
||||
@@ -38,7 +38,8 @@ predicate isInterestingSemiAnchoredRegexpString(string re, string msg) {
|
||||
) and
|
||||
anchorPart = re.regexpCapture(regex, 1) and
|
||||
anchorPart.regexpMatch("(?i).*[a-z].*") and
|
||||
msg = "Misleading operator precedence. The subexpression '" + anchorPart +
|
||||
msg =
|
||||
"Misleading operator precedence. The subexpression '" + anchorPart +
|
||||
"' is anchored, but the other parts of this regular expression are not."
|
||||
)
|
||||
}
|
||||
@@ -53,7 +54,9 @@ predicate isInterestingUnanchoredRegexpString(string re, string msg) {
|
||||
re.regexpMatch("(?i)[():|?a-z0-9-\\\\./]+[.]" + commonTLD() + "([/#?():]\\S*)?") and
|
||||
// without any anchors
|
||||
re.regexpMatch("[^$^]+") and
|
||||
msg = "When this is used as a regular expression on a URL, it may match anywhere, and arbitrary hosts may come before or after it."
|
||||
msg =
|
||||
"When this is used as a regular expression on a URL, it may match anywhere, and arbitrary " +
|
||||
"hosts may come before or after it."
|
||||
}
|
||||
|
||||
class Config extends DataFlow::Configuration {
|
||||
|
||||
@@ -21,5 +21,5 @@ where
|
||||
cfg.hasFlowPath(source, sink) and
|
||||
cfg.isSink(sink.getNode(), allocsz)
|
||||
select sink, source, sink,
|
||||
"This operation, which is used in an $@, involves a potentially large $@ " +
|
||||
"and might overflow.", allocsz, "allocation", source, "value"
|
||||
"This operation, which is used in an $@, involves a potentially large $@ " + "and might overflow.",
|
||||
allocsz, "allocation", source, "value"
|
||||
|
||||
@@ -86,7 +86,8 @@ private predicate isInitialComment(Comment c, File f, int line, int col) {
|
||||
|
||||
/** Gets the `i`th initial comment in `f` (0-based). */
|
||||
private Comment getInitialComment(File f, int i) {
|
||||
result = rank[i + 1](Comment c, int line, int col |
|
||||
result =
|
||||
rank[i + 1](Comment c, int line, int col |
|
||||
isInitialComment(c, f, line, col)
|
||||
|
|
||||
c order by line, col
|
||||
|
||||
@@ -101,7 +101,8 @@ class FuncDef extends @funcdef, StmtParent, ExprParent {
|
||||
|
||||
/** Gets the `i`th result variable of this function. */
|
||||
ResultVariable getResultVar(int i) {
|
||||
result = rank[i + 1](ResultVariable res, int j, int k |
|
||||
result =
|
||||
rank[i + 1](ResultVariable res, int j, int k |
|
||||
res.getDeclaration() = getTypeExpr().getResultDecl(j).getNameExpr(k)
|
||||
|
|
||||
res order by j, k
|
||||
@@ -109,39 +110,29 @@ class FuncDef extends @funcdef, StmtParent, ExprParent {
|
||||
}
|
||||
|
||||
/** Gets a result variable of this function. */
|
||||
ResultVariable getAResultVar() {
|
||||
result.getFunction() = this
|
||||
}
|
||||
ResultVariable getAResultVar() { result.getFunction() = this }
|
||||
|
||||
/**
|
||||
* Gets the `i`th parameter of this function.
|
||||
*
|
||||
* The receiver variable, if any, is considered to be the -1st parameter.
|
||||
*/
|
||||
Parameter getParameter(int i) {
|
||||
result.isParameterOf(this, i)
|
||||
}
|
||||
Parameter getParameter(int i) { result.isParameterOf(this, i) }
|
||||
|
||||
/**
|
||||
* Gets a parameter of this function.
|
||||
*/
|
||||
Parameter getAParameter() {
|
||||
result.getFunction() = this
|
||||
}
|
||||
Parameter getAParameter() { result.getFunction() = this }
|
||||
|
||||
/**
|
||||
* Gets the number of parameters of this function.
|
||||
*/
|
||||
int getNumParameter() {
|
||||
result = count(getAParameter())
|
||||
}
|
||||
int getNumParameter() { result = count(getAParameter()) }
|
||||
|
||||
/**
|
||||
* Gets a call to this function.
|
||||
*/
|
||||
DataFlow::CallNode getACall() {
|
||||
result.getACallee() = this
|
||||
}
|
||||
DataFlow::CallNode getACall() { result.getACallee() = this }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -526,9 +517,7 @@ class ResultVariableDecl extends @field, Documentable, ExprParent {
|
||||
/**
|
||||
* Gets an expression representing the name of a result variable declared in this declaration.
|
||||
*/
|
||||
Expr getANameExpr() {
|
||||
result = getNameExpr(_)
|
||||
}
|
||||
Expr getANameExpr() { result = getNameExpr(_) }
|
||||
|
||||
/**
|
||||
* Gets the function type expression to which this result variable declaration belongs.
|
||||
@@ -549,7 +538,6 @@ class ResultVariableDecl extends @field, Documentable, ExprParent {
|
||||
*/
|
||||
class InterfaceMemberSpec extends @field, Documentable, ExprParent {
|
||||
InterfaceTypeExpr ite;
|
||||
|
||||
int idx;
|
||||
|
||||
InterfaceMemberSpec() { fields(this, ite, idx) }
|
||||
|
||||
@@ -239,11 +239,12 @@ class Parameter extends DeclaredVariable {
|
||||
index = -1
|
||||
or
|
||||
exists(FuncTypeExpr tp | tp = f.getTypeExpr() |
|
||||
this = rank[index + 1](DeclaredVariable parm, int j, int k |
|
||||
parm.getDeclaration() = tp.getParameterDecl(j).getNameExpr(k)
|
||||
|
|
||||
parm order by j, k
|
||||
)
|
||||
this =
|
||||
rank[index + 1](DeclaredVariable parm, int j, int k |
|
||||
parm.getDeclaration() = tp.getParameterDecl(j).getNameExpr(k)
|
||||
|
|
||||
parm order by j, k
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -258,9 +259,7 @@ class Parameter extends DeclaredVariable {
|
||||
int getIndex() { result = index }
|
||||
|
||||
/** Holds if this is the `i`th parameter of function `fd`. */
|
||||
predicate isParameterOf(FuncDef fd, int i) {
|
||||
fd = f and i = index
|
||||
}
|
||||
predicate isParameterOf(FuncDef fd, int i) { fd = f and i = index }
|
||||
}
|
||||
|
||||
/** The receiver variable of a method. */
|
||||
@@ -310,9 +309,7 @@ class Field extends Variable {
|
||||
StructType getDeclaringType() { result = declaringType }
|
||||
|
||||
override Package getPackage() {
|
||||
exists(Type tp | tp.getUnderlyingType() = declaringType |
|
||||
result = tp.getPackage()
|
||||
)
|
||||
exists(Type tp | tp.getUnderlyingType() = declaringType | result = tp.getPackage())
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -430,7 +430,8 @@ class StructType extends @structtype, CompositeType {
|
||||
|
||||
language[monotonicAggregates]
|
||||
override string pp() {
|
||||
result = "struct { " +
|
||||
result =
|
||||
"struct { " +
|
||||
concat(int i, string name, Type tp |
|
||||
component_types(this, i, name, tp)
|
||||
|
|
||||
@@ -488,7 +489,8 @@ class InterfaceType extends @interfacetype, CompositeType {
|
||||
|
||||
language[monotonicAggregates]
|
||||
override string pp() {
|
||||
result = "interface { " +
|
||||
result =
|
||||
"interface { " +
|
||||
concat(string name, Type tp |
|
||||
tp = getMethodType(name)
|
||||
|
|
||||
@@ -506,8 +508,8 @@ class TupleType extends @tupletype, CompositeType {
|
||||
|
||||
language[monotonicAggregates]
|
||||
override string pp() {
|
||||
result = "(" + concat(int i, Type tp | tp = getComponentType(i) | tp.pp(), ", " order by i) +
|
||||
")"
|
||||
result =
|
||||
"(" + concat(int i, Type tp | tp = getComponentType(i) | tp.pp(), ", " order by i) + ")"
|
||||
}
|
||||
|
||||
override string toString() { result = "tuple type" }
|
||||
@@ -529,8 +531,9 @@ class SignatureType extends @signaturetype, CompositeType {
|
||||
|
||||
language[monotonicAggregates]
|
||||
override string pp() {
|
||||
result = "func(" + concat(int i, Type tp | tp = getParameterType(i) | tp.pp(), ", " order by i) +
|
||||
") " + concat(int i, Type tp | tp = getResultType(i) | tp.pp(), ", " order by i)
|
||||
result =
|
||||
"func(" + concat(int i, Type tp | tp = getParameterType(i) | tp.pp(), ", " order by i) + ") " +
|
||||
concat(int i, Type tp | tp = getResultType(i) | tp.pp(), ", " order by i)
|
||||
}
|
||||
|
||||
override string toString() { result = "signature type" }
|
||||
|
||||
@@ -62,6 +62,7 @@ private module Internal {
|
||||
exists(BasicBlock predBB | succBB(predBB, bb) | reachableBB(predBB))
|
||||
}
|
||||
}
|
||||
|
||||
private import Internal
|
||||
|
||||
/** Holds if `dom` is an immediate dominator of `bb`. */
|
||||
|
||||
@@ -1287,7 +1287,7 @@ module CFG {
|
||||
private MkEntryNode getEntry() { result = MkEntryNode(this) }
|
||||
|
||||
private Parameter getParameterRanked(int i) {
|
||||
result = rank[i+1](Parameter p, int j | p = getParameter(j) | p order by j)
|
||||
result = rank[i + 1](Parameter p, int j | p = getParameter(j) | p order by j)
|
||||
}
|
||||
|
||||
private ControlFlow::Node getPrologueNode(int i) {
|
||||
|
||||
@@ -10,8 +10,7 @@ import go
|
||||
* or the receiver parameter.
|
||||
*/
|
||||
private newtype TFunctionInput =
|
||||
TInParameter(int i) { exists(SignatureType s | exists(s.getParameterType(i))) }
|
||||
or
|
||||
TInParameter(int i) { exists(SignatureType s | exists(s.getParameterType(i))) } or
|
||||
TInReceiver()
|
||||
|
||||
/**
|
||||
@@ -20,14 +19,10 @@ private newtype TFunctionInput =
|
||||
*/
|
||||
class FunctionInput extends TFunctionInput {
|
||||
/** Holds if this represents the `i`th parameter of a function. */
|
||||
predicate isParameter(int i) {
|
||||
none()
|
||||
}
|
||||
predicate isParameter(int i) { none() }
|
||||
|
||||
/** Holds if this represents the receiver of a function. */
|
||||
predicate isReceiver() {
|
||||
none()
|
||||
}
|
||||
predicate isReceiver() { none() }
|
||||
|
||||
/** Gets the data-flow node corresponding to this input for the call `c`. */
|
||||
final DataFlow::Node getNode(DataFlow::CallNode c) { result = getEntryNode(c) }
|
||||
@@ -46,32 +41,22 @@ class FunctionInput extends TFunctionInput {
|
||||
private class ParameterInput extends FunctionInput, TInParameter {
|
||||
int index;
|
||||
|
||||
ParameterInput() {
|
||||
this = TInParameter(index)
|
||||
}
|
||||
ParameterInput() { this = TInParameter(index) }
|
||||
|
||||
override predicate isParameter(int i) {
|
||||
i = index
|
||||
}
|
||||
override predicate isParameter(int i) { i = index }
|
||||
|
||||
override DataFlow::Node getEntryNode(DataFlow::CallNode c) {
|
||||
result = c.getArgument(index)
|
||||
}
|
||||
override DataFlow::Node getEntryNode(DataFlow::CallNode c) { result = c.getArgument(index) }
|
||||
|
||||
override DataFlow::Node getExitNode(FuncDef f) {
|
||||
result = DataFlow::parameterNode(f.getParameter(index))
|
||||
}
|
||||
|
||||
override string toString() {
|
||||
result = "parameter " + index
|
||||
}
|
||||
override string toString() { result = "parameter " + index }
|
||||
}
|
||||
|
||||
/** The receiver of a function, viewed as a source of input. */
|
||||
private class ReceiverInput extends FunctionInput, TInReceiver {
|
||||
override predicate isReceiver() {
|
||||
any()
|
||||
}
|
||||
override predicate isReceiver() { any() }
|
||||
|
||||
override DataFlow::Node getEntryNode(DataFlow::CallNode c) {
|
||||
result = c.(DataFlow::MethodCallNode).getReceiver()
|
||||
@@ -81,9 +66,7 @@ private class ReceiverInput extends FunctionInput, TInReceiver {
|
||||
result = DataFlow::receiverNode(f.(MethodDecl).getReceiver())
|
||||
}
|
||||
|
||||
override string toString() {
|
||||
result = "receiver"
|
||||
}
|
||||
override string toString() { result = "receiver" }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,8 +79,7 @@ private newtype TFunctionOutput =
|
||||
or
|
||||
// one among several results
|
||||
exists(SignatureType s | exists(s.getResultType(index)))
|
||||
}
|
||||
or
|
||||
} or
|
||||
TOutParameter(int index) {
|
||||
// the receiver parameter
|
||||
index = -1
|
||||
@@ -112,24 +94,16 @@ private newtype TFunctionOutput =
|
||||
*/
|
||||
class FunctionOutput extends TFunctionOutput {
|
||||
/** Holds if this represents the (single) result of a function. */
|
||||
predicate isResult() {
|
||||
none()
|
||||
}
|
||||
predicate isResult() { none() }
|
||||
|
||||
/** Holds if this represents the `i`th result of a function. */
|
||||
predicate isResult(int i) {
|
||||
none()
|
||||
}
|
||||
predicate isResult(int i) { none() }
|
||||
|
||||
/** Holds if this represents the receiver of a function. */
|
||||
predicate isReceiver() {
|
||||
none()
|
||||
}
|
||||
predicate isReceiver() { none() }
|
||||
|
||||
/** Holds if this represents the `i`th parameter of a function. */
|
||||
predicate isParameter(int i) {
|
||||
none()
|
||||
}
|
||||
predicate isParameter(int i) { none() }
|
||||
|
||||
/** Gets the data-flow node corresponding to this output for the call `c`. */
|
||||
final DataFlow::Node getNode(DataFlow::CallNode c) { result = getExitNode(c) }
|
||||
@@ -148,17 +122,11 @@ class FunctionOutput extends TFunctionOutput {
|
||||
private class OutResult extends FunctionOutput, TOutResult {
|
||||
int index;
|
||||
|
||||
OutResult() {
|
||||
this = TOutResult(index)
|
||||
}
|
||||
OutResult() { this = TOutResult(index) }
|
||||
|
||||
override predicate isResult() {
|
||||
index = -1
|
||||
}
|
||||
override predicate isResult() { index = -1 }
|
||||
|
||||
override predicate isResult(int i) {
|
||||
i = index and i >= 0
|
||||
}
|
||||
override predicate isResult(int i) { i = index and i >= 0 }
|
||||
|
||||
override DataFlow::Node getEntryNode(FuncDef f) {
|
||||
// return expressions
|
||||
@@ -200,17 +168,11 @@ private class OutResult extends FunctionOutput, TOutResult {
|
||||
private class OutParameter extends FunctionOutput, TOutParameter {
|
||||
int index;
|
||||
|
||||
OutParameter() {
|
||||
this = TOutParameter(index)
|
||||
}
|
||||
OutParameter() { this = TOutParameter(index) }
|
||||
|
||||
override predicate isReceiver() {
|
||||
index = -1
|
||||
}
|
||||
override predicate isReceiver() { index = -1 }
|
||||
|
||||
override predicate isParameter(int i) {
|
||||
i = index and i >= 0
|
||||
}
|
||||
override predicate isParameter(int i) { i = index and i >= 0 }
|
||||
|
||||
override DataFlow::Node getEntryNode(FuncDef f) {
|
||||
// there is no generic way of assigning to a parameter; operations that taint a parameter
|
||||
|
||||
@@ -52,8 +52,7 @@ private predicate isConcreteInterfaceCall(DataFlow::Node call, DataFlow::Node re
|
||||
* but its concrete types can be determined by local reasoning.
|
||||
*/
|
||||
private FuncDecl getConcreteTarget(DataFlow::CallNode call) {
|
||||
exists(DataFlow::Node recv, string m |
|
||||
isConcreteInterfaceCall(call, recv, m) |
|
||||
exists(DataFlow::Node recv, string m | isConcreteInterfaceCall(call, recv, m) |
|
||||
exists(Type concreteReceiverType, DeclaredFunction concreteTarget |
|
||||
concreteReceiverType = getConcreteType(getInterfaceCallReceiverSource(call)) and
|
||||
concreteTarget = concreteReceiverType.getMethod(m) and
|
||||
|
||||
@@ -76,15 +76,11 @@ module SQL {
|
||||
|
||||
/** A string that might identify package `go-pg/pg` or a specific version of it. */
|
||||
bindingset[result]
|
||||
private string gopg() {
|
||||
result.regexpMatch("github.com/go-pg/pg(/v[^/]+)?")
|
||||
}
|
||||
private string gopg() { result.regexpMatch("github.com/go-pg/pg(/v[^/]+)?") }
|
||||
|
||||
/** A string that might identify package `go-pg/pg/orm` or a specific version of it. */
|
||||
bindingset[result]
|
||||
private string gopgorm() {
|
||||
result.regexpMatch("github.com/go-pg/pg(/v[^/]+)?/orm")
|
||||
}
|
||||
private string gopgorm() { result.regexpMatch("github.com/go-pg/pg(/v[^/]+)?/orm") }
|
||||
|
||||
/**
|
||||
* A string argument to an API of `go-pg/pg` that is directly interpreted as SQL without
|
||||
@@ -120,9 +116,7 @@ module SQL {
|
||||
f.hasQualifiedName(gopgorm(), "Q") and
|
||||
arg = 0
|
||||
or
|
||||
exists(string tp, string m |
|
||||
f.(Method).hasQualifiedName(gopgorm(), tp, m)
|
||||
|
|
||||
exists(string tp, string m | f.(Method).hasQualifiedName(gopgorm(), tp, m) |
|
||||
tp = "Query" and
|
||||
(
|
||||
m = "ColumnExpr" or
|
||||
|
||||
@@ -9,7 +9,8 @@ string complexToString(float real, float imag) {
|
||||
string longString(Expr e) {
|
||||
if e instanceof BinaryExpr
|
||||
then
|
||||
result = longString(e.(BinaryExpr).getLeftOperand()) + " " + e.(BinaryExpr).getOperator() + " " +
|
||||
result =
|
||||
longString(e.(BinaryExpr).getLeftOperand()) + " " + e.(BinaryExpr).getOperator() + " " +
|
||||
longString(e.(BinaryExpr).getRightOperand())
|
||||
else result = e.toString()
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import go
|
||||
|
||||
from FunctionInput inp, DataFlow::CallNode c
|
||||
select inp, c, inp.getEntryNode(c)
|
||||
select inp, c, inp.getEntryNode(c)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import go
|
||||
|
||||
from FunctionInput inp, FuncDef f
|
||||
select inp, f, inp.getExitNode(f)
|
||||
select inp, f, inp.getExitNode(f)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import go
|
||||
|
||||
from FunctionOutput outp, FuncDef f
|
||||
select outp, f, outp.getEntryNode(f)
|
||||
select outp, f, outp.getEntryNode(f)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import go
|
||||
|
||||
from FunctionOutput outp, DataFlow::CallNode c
|
||||
select outp, c, outp.getExitNode(c)
|
||||
select outp, c, outp.getExitNode(c)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import go
|
||||
|
||||
// This test should not have any results
|
||||
|
||||
from DataFlow::Node nd, int n
|
||||
where n = count(globalValueNumber(nd)) and n != 1
|
||||
select nd, n
|
||||
|
||||
Reference in New Issue
Block a user