Skip to content

Commit dbf2673

Browse files
committed
add returnsFormatted predicate to PrintfStyleCall (similar to JS)
1 parent 46627a7 commit dbf2673

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

ruby/ql/lib/codeql/ruby/security/TaintedFormatStringSpecific.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ abstract class PrintfStyleCall extends DataFlow::CallNode {
2525
* Gets then `n`th formatted argument of this call.
2626
*/
2727
DataFlow::Node getFormatArgument(int n) { n >= 0 and result = this.getArgument(n + 1) }
28+
29+
/** Holds if this call returns the formatted string. */
30+
predicate returnsFormatted() { any() }
2831
}
2932

3033
/**
@@ -50,6 +53,8 @@ class KernelPrintfCall extends PrintfStyleCall {
5053
then result = this.getArgument(0)
5154
else result = this.getArgument([0, 1])
5255
}
56+
57+
override predicate returnsFormatted() { none() }
5358
}
5459

5560
/**
@@ -62,6 +67,8 @@ class KernelSprintfCall extends PrintfStyleCall {
6267
this.asExpr().getExpr() instanceof UnknownMethodCall and
6368
this.getMethodName() = "sprintf"
6469
}
70+
71+
override predicate returnsFormatted() { any() }
6572
}
6673

6774
/**
@@ -71,4 +78,6 @@ class IOPrintfCall extends PrintfStyleCall {
7178
IOPrintfCall() {
7279
this.getReceiver() instanceof IO::IOInstance and this.getMethodName() = "printf"
7380
}
81+
82+
override predicate returnsFormatted() { none() }
7483
}

0 commit comments

Comments
 (0)