Skip to content

Commit db82015

Browse files
intrigus-lgtmripatel-fd
authored andcommitted
codeql: add fd_join check query
1 parent f539bec commit db82015

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

contrib/codeql/dev/JoinCheck.ql

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @name Checks for suspicious joins
3+
* @description This query checks for calls to `fd_*_join` where the argument does not match the expected type.
4+
* @precision high
5+
* @kind problem
6+
* @tags security, correctness
7+
* @id asymmetric-research/join-check
8+
* @problem.severity warning
9+
*/
10+
11+
import cpp
12+
13+
class FdJoinCall extends Call {
14+
FdJoinCall() {
15+
this.getTarget().getName().matches("fd_%_join") and
16+
this.getTarget().getParameter(0).getType().(PointerType).getBaseType() instanceof VoidType and
17+
not this.getType() instanceof VoidType
18+
}
19+
}
20+
21+
predicate isCompatible(DerivedType t, DerivedType expected) {
22+
t.getBaseType() = expected.getBaseType()
23+
}
24+
25+
class RelevantType extends Type {
26+
RelevantType() {
27+
not this.(DerivedType).getBaseType() instanceof VoidType and
28+
not this.(DerivedType).getBaseType() instanceof CharType and
29+
not this instanceof IntegralType
30+
}
31+
}
32+
33+
from FdJoinCall call, Expr arg, Type t, Type expectedType
34+
where
35+
arg = call.getArgument(0) and
36+
t = arg.getType() and
37+
expectedType = call.getType() and
38+
not isCompatible(t, expectedType) and
39+
t.getUnspecifiedType() instanceof RelevantType
40+
select call, "The $@ to $@ has type $@, but the parameter type is $@.", arg, "argument", call,
41+
call.toString(), t, t.toString(), expectedType, expectedType.toString()

0 commit comments

Comments
 (0)