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

Commit 2a7754a

Browse files
committed
Factor ErrorType out of two duplicate tests
1 parent 4b6810e commit 2a7754a

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

ql/src/InconsistentCode/MissingErrorCheck.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ predicate returnUncheckedAtNode(
9090
err.getAPredecessor() = call.getResult(1) and
9191
call.asInstruction() = node and
9292
isDereferenceableType(ptr.getType()) and
93-
err.getType().implements(Builtin::error().getType().getUnderlyingType()) and
93+
err.getType() instanceof ErrorType and
9494
calleeMayReturnNilWithError(call)
9595
or
9696
// Recursive case: check that some predecessor is missing a check, and `node` does not itself

ql/src/Security/CWE-327/InsecureTLS.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ predicate isReturnedWithError(DataFlow::Node node) {
5959
exists(ReturnStmt ret |
6060
ret.getExpr(0) = node.asExpr() and
6161
ret.getNumExpr() = 2 and
62-
ret.getExpr(1).getType().implements(Builtin::error().getType().getUnderlyingType())
62+
ret.getExpr(1).getType() instanceof ErrorType
6363
// That last condition implies ret.getExpr(1) is non-nil, since nil doesn't implement `error`
6464
)
6565
}

ql/src/semmle/go/Types.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,13 @@ class NamedType extends @namedtype, CompositeType {
630630
override Type getUnderlyingType() { result = getBaseType().getUnderlyingType() }
631631
}
632632

633+
/**
634+
* A type that implements the builtin interface `error`.
635+
*/
636+
class ErrorType extends Type {
637+
ErrorType() { this.implements(Builtin::error().getType().getUnderlyingType()) }
638+
}
639+
633640
/**
634641
* Holds if `i` is the empty interface type, which is implemented by every type with a method set.
635642
*/

0 commit comments

Comments
 (0)