add returnsFormatted predicate to PrintfStyleCall (similar to JS)

This commit is contained in:
erik-krogh
2022-10-14 16:06:10 +02:00
parent 46627a737e
commit dbf2673a91

View File

@@ -25,6 +25,9 @@ abstract class PrintfStyleCall extends DataFlow::CallNode {
* Gets then `n`th formatted argument of this call.
*/
DataFlow::Node getFormatArgument(int n) { n >= 0 and result = this.getArgument(n + 1) }
/** Holds if this call returns the formatted string. */
predicate returnsFormatted() { any() }
}
/**
@@ -50,6 +53,8 @@ class KernelPrintfCall extends PrintfStyleCall {
then result = this.getArgument(0)
else result = this.getArgument([0, 1])
}
override predicate returnsFormatted() { none() }
}
/**
@@ -62,6 +67,8 @@ class KernelSprintfCall extends PrintfStyleCall {
this.asExpr().getExpr() instanceof UnknownMethodCall and
this.getMethodName() = "sprintf"
}
override predicate returnsFormatted() { any() }
}
/**
@@ -71,4 +78,6 @@ class IOPrintfCall extends PrintfStyleCall {
IOPrintfCall() {
this.getReceiver() instanceof IO::IOInstance and this.getMethodName() = "printf"
}
override predicate returnsFormatted() { none() }
}