Skip to content

Commit 6de1abc

Browse files
committed
add a returnsFormatted predicate to the printf model, similar to the JS implementation
1 parent a2b924b commit 6de1abc

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

ruby/ql/lib/codeql/ruby/frameworks/StringFormatters.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ abstract class PrintfStyleCall extends DataFlow::CallNode {
2121
* Gets then `n`th formatted argument of this call.
2222
*/
2323
DataFlow::Node getFormatArgument(int n) { n >= 0 and result = this.getArgument(n + 1) }
24+
25+
/** Holds if this call returns the formatted string. */
26+
predicate returnsFormatted() { any() }
2427
}
2528

2629
/**
@@ -46,6 +49,8 @@ class KernelPrintfCall extends PrintfStyleCall {
4649
then result = this.getArgument(0)
4750
else result = this.getArgument([0, 1])
4851
}
52+
53+
override predicate returnsFormatted() { none() }
4954
}
5055

5156
/**
@@ -58,6 +63,8 @@ class KernelSprintfCall extends PrintfStyleCall {
5863
this.asExpr().getExpr() instanceof UnknownMethodCall and
5964
this.getMethodName() = "sprintf"
6065
}
66+
67+
override predicate returnsFormatted() { any() }
6168
}
6269

6370
/**
@@ -67,4 +74,6 @@ class IOPrintfCall extends PrintfStyleCall {
6774
IOPrintfCall() {
6875
this.getReceiver() instanceof IO::IOInstance and this.getMethodName() = "printf"
6976
}
77+
78+
override predicate returnsFormatted() { none() }
7079
}

0 commit comments

Comments
 (0)