Skip to content

Commit 8abaf12

Browse files
committed
C++: Clean up result not checked query.
1 parent 5ffbf56 commit 8abaf12

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

cpp/ql/src/Security/CWE/CWE-295/SSLResultNotChecked.ql

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import cpp
1515
import semmle.code.cpp.valuenumbering.GlobalValueNumbering
16-
//import semmle.code.cpp.controlflow.Guards
1716
import semmle.code.cpp.controlflow.IRGuards
1817

1918
/**
@@ -24,7 +23,7 @@ class SSLGetPeerCertificateCall extends FunctionCall {
2423
getTarget().getName() = "SSL_get_peer_certificate" // SSL_get_peer_certificate(ssl)
2524
}
2625

27-
// TODO: getSSLArg?
26+
Expr getSSLArgument() { result = getArgument(0) }
2827
}
2928

3029
/**
@@ -34,6 +33,8 @@ class SSLGetVerifyResultCall extends FunctionCall {
3433
SSLGetVerifyResultCall() {
3534
getTarget().getName() = "SSL_get_verify_result" // SSL_get_peer_certificate(ssl)
3635
}
36+
37+
Expr getSSLArgument() { result = getArgument(0) }
3738
}
3839

3940
/**
@@ -42,8 +43,8 @@ class SSLGetVerifyResultCall extends FunctionCall {
4243
*/
4344
predicate resultIsChecked(SSLGetPeerCertificateCall getCertCall, ControlFlowNode node) {
4445
exists(Expr ssl, SSLGetVerifyResultCall check |
45-
ssl = globalValueNumber(getCertCall.getArgument(0)).getAnExpr() and
46-
ssl = check.getArgument(0) and
46+
ssl = globalValueNumber(getCertCall.getSSLArgument()).getAnExpr() and
47+
ssl = check.getSSLArgument() and
4748
node = check
4849
)
4950
}
@@ -61,20 +62,24 @@ predicate certIsZero(SSLGetPeerCertificateCall getCertCall, ControlFlowNode node
6162
node1 = guard and
6263
(
6364
(
64-
guard.comparesEq(cert, zero, 0, true, true) and // if (cert == zero) {
65+
// if (cert == zero) {
66+
guard.comparesEq(cert, zero, 0, true, true) and
6567
node2 = guard.getATrueSuccessor()
6668
) or (
67-
guard.comparesEq(cert, zero, 0, false, true) and // if (cert != zero) { }
69+
// if (cert != zero) { }
70+
guard.comparesEq(cert, zero, 0, false, true) and
6871
node2 = guard.getAFalseSuccessor()
6972
)
7073
)
7174
) or (
72-
guard = cert and // if (cert) { }
75+
// if (cert) { }
76+
guard = cert and
7377
node1 = guard and
7478
node2 = guard.getAFalseSuccessor()
7579
) or (
80+
// if (!cert) {
7681
node1 = guard.getParent() and
77-
node2 = guard.getParent().(NotExpr).getATrueSuccessor() // if (!cert) {
82+
node2 = guard.getParent().(NotExpr).getATrueSuccessor()
7883
)
7984
)
8085
)

0 commit comments

Comments
 (0)