Skip to content

Commit 106dc1a

Browse files
committed
Fix violations of ql/if-with-none.
1 parent 8ee5d76 commit 106dc1a

File tree

9 files changed

+221
-241
lines changed

9 files changed

+221
-241
lines changed

actions/ql/lib/codeql/actions/ast/internal/Ast.qll

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,11 @@ abstract class AstNodeImpl extends TAstNode {
125125
* Gets the enclosing Step.
126126
*/
127127
StepImpl getEnclosingStep() {
128-
if this instanceof StepImpl
129-
then result = this
130-
else
131-
if this instanceof ScalarValueImpl
132-
then result.getAChildNode*() = this.getParentNode()
133-
else none()
128+
this instanceof StepImpl and
129+
result = this
130+
or
131+
this instanceof ScalarValueImpl and
132+
result.getAChildNode*() = this.getParentNode()
134133
}
135134

136135
/**
@@ -1416,9 +1415,8 @@ class ExternalJobImpl extends JobImpl, UsesImpl {
14161415
override string getVersion() {
14171416
exists(YamlString name |
14181417
n.lookup("uses") = name and
1419-
if not name.getValue().matches("\\.%")
1420-
then result = name.getValue().regexpCapture(repoUsesParser(), 4)
1421-
else none()
1418+
not name.getValue().matches("\\.%") and
1419+
result = name.getValue().regexpCapture(repoUsesParser(), 4)
14221420
)
14231421
}
14241422
}

actions/ql/lib/codeql/actions/dataflow/ExternalFlow.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ predicate madSource(DataFlow::Node source, string kind, string fieldName) {
6363
(
6464
if fieldName.trim().matches("env.%")
6565
then source.asExpr() = uses.getInScopeEnvVarExpr(fieldName.trim().replaceAll("env.", ""))
66-
else
67-
if fieldName.trim().matches("output.%")
68-
then source.asExpr() = uses
69-
else none()
66+
else (
67+
fieldName.trim().matches("output.%") and
68+
source.asExpr() = uses
69+
)
7070
)
7171
)
7272
}

actions/ql/lib/codeql/actions/security/ArtifactPoisoningQuery.qll

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ class ActionsGitHubScriptDownloadStep extends UntrustedArtifactDownloadStep, Use
171171
.getScript()
172172
.getACommand()
173173
.regexpCapture(unzipRegexp() + unzipDirArgRegexp(), 3)))
174-
else
175-
if this.getAFollowingStep().(Run).getScript().getACommand().regexpMatch(unzipRegexp())
176-
then result = "GITHUB_WORKSPACE/"
177-
else none()
174+
else (
175+
this.getAFollowingStep().(Run).getScript().getACommand().regexpMatch(unzipRegexp()) and
176+
result = "GITHUB_WORKSPACE/"
177+
)
178178
}
179179
}
180180

@@ -207,12 +207,13 @@ class GHRunArtifactDownloadStep extends UntrustedArtifactDownloadStep, Run {
207207
.getScript()
208208
.getACommand()
209209
.regexpCapture(unzipRegexp() + unzipDirArgRegexp(), 3)))
210-
else
211-
if
210+
else (
211+
(
212212
this.getAFollowingStep().(Run).getScript().getACommand().regexpMatch(unzipRegexp()) or
213213
this.getScript().getACommand().regexpMatch(unzipRegexp())
214-
then result = "GITHUB_WORKSPACE/"
215-
else none()
214+
) and
215+
result = "GITHUB_WORKSPACE/"
216+
)
216217
}
217218
}
218219

cpp/ql/lib/experimental/semmle/code/cpp/rangeanalysis/RangeAnalysis.qll

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,11 @@ private predicate boundFlowStep(Instruction i, NonPhiOperand op, int delta, bool
298298
else
299299
if strictlyNegative(x)
300300
then upper = true and delta = -1
301-
else
302-
if negative(x)
303-
then upper = true and delta = 0
304-
else none()
301+
else (
302+
negative(x) and
303+
upper = true and
304+
delta = 0
305+
)
305306
)
306307
or
307308
exists(Operand x |
@@ -321,10 +322,11 @@ private predicate boundFlowStep(Instruction i, NonPhiOperand op, int delta, bool
321322
else
322323
if strictlyNegative(x)
323324
then upper = false and delta = 1
324-
else
325-
if negative(x)
326-
then upper = false and delta = 0
327-
else none()
325+
else (
326+
negative(x) and
327+
upper = false and
328+
delta = 0
329+
)
328330
)
329331
or
330332
i.(RemInstruction).getRightOperand() = op and positive(op) and delta = -1 and upper = true

cpp/ql/src/Security/CWE/CWE-190/IntegerOverflowTainted.ql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import semmle.code.cpp.controlflow.IRGuards as IRGuards
2525
predicate outOfBoundsExpr(Expr expr, string kind) {
2626
if convertedExprMightOverflowPositively(expr)
2727
then kind = "overflow"
28-
else
29-
if convertedExprMightOverflowNegatively(expr)
30-
then kind = "overflow negatively"
31-
else none()
28+
else (
29+
convertedExprMightOverflowNegatively(expr) and
30+
kind = "overflow negatively"
31+
)
3232
}
3333

3434
predicate isSource(FS::FlowSource source, string sourceType) { sourceType = source.getSourceType() }

0 commit comments

Comments
 (0)