33 * format injections, as well as extension points for adding your own.
44 */
55
6- private import ruby
7- private import codeql.ruby.DataFlow
8- private import codeql.ruby.dataflow.RemoteFlowSources
9- private import codeql.ruby.ApiGraphs
10-
116/**
127 * Provides default sources, sinks and sanitizers for reasoning about
138 * format injections, as well as extension points for adding your own.
149 */
1510module TaintedFormatString {
11+ import TaintedFormatStringSpecific
12+
1613 /**
1714 * A data flow source for format injections.
1815 */
@@ -36,63 +33,11 @@ module TaintedFormatString {
3633 */
3734 class FormatSink extends Sink {
3835 FormatSink ( ) {
39- exists ( PrintfCall printf |
36+ exists ( PrintfStyleCall printf |
4037 this = printf .getFormatString ( ) and
4138 // exclude trivial case where there are no arguments to interpolate
4239 exists ( printf .getFormatArgument ( _) )
4340 )
4441 }
4542 }
46-
47- /**
48- * A call to `printf` or `sprintf`.
49- */
50- abstract class PrintfCall extends DataFlow:: CallNode {
51- // We assume that most printf-like calls have the signature f(format_string, args...)
52- /**
53- * Gets the format string of this call.
54- */
55- DataFlow:: Node getFormatString ( ) { result = this .getArgument ( 0 ) }
56-
57- /**
58- * Gets then `n`th formatted argument of this call.
59- */
60- DataFlow:: Node getFormatArgument ( int n ) { n > 0 and result = this .getArgument ( n ) }
61- }
62-
63- /**
64- * A call to `Kernel.printf`.
65- */
66- class KernelPrintfCall extends PrintfCall {
67- KernelPrintfCall ( ) {
68- this = API:: getTopLevelMember ( "Kernel" ) .getAMethodCall ( "printf" )
69- or
70- this .asExpr ( ) .getExpr ( ) instanceof UnknownMethodCall and
71- this .getMethodName ( ) = "printf"
72- }
73-
74- // Kernel#printf supports two signatures:
75- // printf(io, string, ...)
76- // printf(string, ...)
77- override DataFlow:: Node getFormatString ( ) { result = this .getArgument ( [ 0 , 1 ] ) }
78- }
79-
80- /**
81- * A call to `Kernel.sprintf`.
82- */
83- class KernelSprintfCall extends PrintfCall {
84- KernelSprintfCall ( ) {
85- this = API:: getTopLevelMember ( "Kernel" ) .getAMethodCall ( "sprintf" )
86- or
87- this .asExpr ( ) .getExpr ( ) instanceof UnknownMethodCall and
88- this .getMethodName ( ) = "sprintf"
89- }
90- }
91-
92- /**
93- * A call to `IO#printf`.
94- */
95- class IOPrintfCall extends PrintfCall {
96- IOPrintfCall ( ) { this = API:: getTopLevelMember ( "IO" ) .getInstance ( ) .getAMethodCall ( "printf" ) }
97- }
9843}
0 commit comments