Skip to content

Commit 82b92c3

Browse files
committed
Swift: Change method types to DataFlow::Node / go ahead with planned deprecations.
1 parent bfd150a commit 82b92c3

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

swift/ql/lib/codeql/swift/regex/Regex.qll

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ abstract class RegexCreation extends DataFlow::Node {
6969
abstract DataFlow::Node getStringInput();
7070

7171
/**
72-
* Gets a dataflow node for an options input that might contain parse mode
73-
* flags (if any).
72+
* Gets a dataflow node for an options input that might contain options
73+
* such as parse mode flags (if any).
7474
*/
7575
DataFlow::Node getAnOptionsInput() { none() }
7676

@@ -307,16 +307,26 @@ abstract class RegexEval extends CallExpr {
307307
* Consider using `getARegex()` instead (which tracks the regular expression
308308
* input back to its source).
309309
*/
310-
abstract Expr getRegexInput();
310+
abstract DataFlow::Node getRegexInputNode();
311+
312+
/**
313+
* DEPRECATED: Use `getRegexInputNode()` instead.
314+
*/
315+
deprecated Expr getRegexInput() { result = this.getRegexInputNode().asExpr() }
311316

312317
/**
313318
* Gets the input to this call that is the string the regular expression is evaluated on.
314319
*/
315-
abstract Expr getStringInput();
320+
abstract DataFlow::Node getStringInputNode();
321+
322+
/**
323+
* DEPRECATED: Use `getStringInputNode()` instead.
324+
*/
325+
deprecated Expr getStringInput() { result = this.getStringInputNode().asExpr() }
316326

317327
/**
318-
* Gets a dataflow node for an options input that might contain parse mode
319-
* flags (if any).
328+
* Gets a dataflow node for an options input that might contain options such
329+
* as parse mode flags (if any).
320330
*/
321331
DataFlow::Node getAnOptionsInput() { none() }
322332

@@ -325,13 +335,12 @@ abstract class RegexEval extends CallExpr {
325335
*/
326336
RegExp getARegex() {
327337
// string literal used directly as a regex
328-
DataFlow::exprNode(result).(ParsedStringRegex).getAParse() =
329-
DataFlow::exprNode(this.getRegexInput())
338+
DataFlow::exprNode(result).(ParsedStringRegex).getAParse() = this.getRegexInputNode()
330339
or
331340
// string literal -> regex object -> use
332341
exists(RegexCreation regexCreation |
333342
DataFlow::exprNode(result).(ParsedStringRegex).getAParse() = regexCreation.getStringInput() and
334-
RegexUseFlow::flow(regexCreation, DataFlow::exprNode(this.getRegexInput()))
343+
RegexUseFlow::flow(regexCreation, this.getRegexInputNode())
335344
)
336345
}
337346

@@ -345,7 +354,7 @@ abstract class RegexEval extends CallExpr {
345354
any(RegexAdditionalFlowStep s).setsParseMode(setNode, result, true) and
346355
// reaches this eval
347356
(
348-
RegexParseModeFlow::flow(setNode, DataFlow::exprNode(this.getRegexInput())) or
357+
RegexParseModeFlow::flow(setNode, this.getRegexInputNode()) or
349358
RegexParseModeFlow::flow(setNode, this.getAnOptionsInput())
350359
)
351360
)
@@ -404,9 +413,9 @@ private class AlwaysRegexEval extends RegexEval {
404413
stringInput.asExpr() = this.getQualifier()
405414
}
406415

407-
override Expr getRegexInput() { result = regexInput.asExpr() }
416+
override DataFlow::Node getRegexInputNode() { result = regexInput }
408417

409-
override Expr getStringInput() { result = stringInput.asExpr() }
418+
override DataFlow::Node getStringInputNode() { result = stringInput }
410419
}
411420

412421
/**
@@ -489,9 +498,9 @@ private class NSStringCompareOptionsRegexEval extends RegexEval {
489498
NSStringCompareOptionsFlagFlow::flow(_, potentialEval.getAnOptionsInput())
490499
}
491500

492-
override Expr getRegexInput() { result = potentialEval.getRegexInput().asExpr() }
501+
override DataFlow::Node getRegexInputNode() { result = potentialEval.getRegexInput() }
493502

494-
override Expr getStringInput() { result = potentialEval.getStringInput().asExpr() }
503+
override DataFlow::Node getStringInputNode() { result = potentialEval.getStringInput() }
495504

496505
override DataFlow::Node getAnOptionsInput() { result = potentialEval.getAnOptionsInput() }
497506
}

swift/ql/lib/codeql/swift/regex/internal/RegexTracking.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ private module StringLiteralUseConfig implements DataFlow::ConfigSig {
2020

2121
predicate isSink(DataFlow::Node node) {
2222
// evaluated directly as a regular expression
23-
node.asExpr() = any(RegexEval eval).getRegexInput()
23+
node = any(RegexEval eval).getRegexInputNode()
2424
or
2525
// used to create a regular expression object
2626
node = any(RegexCreation regexCreation).getStringInput()
@@ -41,7 +41,7 @@ private module RegexUseConfig implements DataFlow::ConfigSig {
4141

4242
predicate isSink(DataFlow::Node node) {
4343
// evaluation of the regex
44-
node.asExpr() = any(RegexEval eval).getRegexInput()
44+
node = any(RegexEval eval).getRegexInputNode()
4545
}
4646

4747
predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
@@ -67,7 +67,7 @@ private module RegexParseModeConfig implements DataFlow::StateConfigSig {
6767
predicate isSink(DataFlow::Node node, FlowState flowstate) {
6868
// evaluation of a regex
6969
(
70-
node.asExpr() = any(RegexEval eval).getRegexInput() or
70+
node = any(RegexEval eval).getRegexInputNode() or
7171
node = any(RegexEval eval).getAnOptionsInput()
7272
) and
7373
exists(flowstate)

swift/ql/test/library-tests/regex/regex.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module RegexTest implements TestSig {
6060

6161
predicate hasOptionalResult(Location location, string element, string tag, string value) {
6262
exists(RegexEval eval, Expr input |
63-
eval.getStringInput() = input and
63+
eval.getStringInputNode().asExpr() = input and
6464
location = input.getLocation() and
6565
element = input.toString() and
6666
tag = "input" and

0 commit comments

Comments
 (0)