Skip to content

Commit a6a30b3

Browse files
committed
C++: clarify ScanfOutput.getMinimumGuardConstant()
1 parent e39229d commit a6a30b3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

cpp/ql/src/Critical/MissingCheckScanf.ql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@ class ScanfOutput extends Expr {
3333
ScanfFunctionCall getCall() { result = call }
3434

3535
/**
36-
* Any subsequent use of this argument should be surrounded by a
37-
* check ensuring that the `scanf`-like function has returned a value
38-
* equal to at least `getMinimumGuardConstant()`.
36+
* Returns the smallest possible `scanf` return value that would indicate
37+
* success in writing this output argument.
3938
*/
4039
int getMinimumGuardConstant() {
4140
result =
4241
varargIndex + 1 -
4342
count(ScanfFormatLiteral f, int n |
44-
n <= varargIndex and f.getUse() = call and f.parseConvSpec(n, _, _, _, "n")
43+
// Special case: %n writes to an argument without reading any input.
44+
// It does not increase the count returned by `scanf`.
45+
n <= varargIndex and f.getUse() = call and f.getConversionChar(n) = "n"
4546
)
4647
}
4748

0 commit comments

Comments
 (0)