Skip to content

Commit af00e46

Browse files
committed
C++: Mark fprintf and friends as a partial write of the stream argument.
1 parent 6a57da7 commit af00e46

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

cpp/ql/lib/semmle/code/cpp/models/interfaces/FormattingFunction.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,16 @@ abstract class FormattingFunction extends ArrayFunction, TaintFunction {
170170
output.isParameterDeref(this.getOutputParameterIndex(_))
171171
)
172172
}
173+
174+
final override predicate isPartialWrite(FunctionOutput output) {
175+
exists(int outputParameterIndex |
176+
output.isParameterDeref(outputParameterIndex) and
177+
// We require the output to be a stream since that definitely means that
178+
// it's a partial write. If it's not a stream then it will most likely
179+
// fill the whole buffer.
180+
outputParameterIndex = this.getOutputParameterIndex(true)
181+
)
182+
}
173183
}
174184

175185
/**

cpp/ql/test/library-tests/dataflow/taint-tests/taint.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,6 @@ int f7(void)
840840
{
841841
FILE* fp = (FILE*)indirect_source();
842842
fprintf(fp, "");
843-
indirect_sink(fp); // $ MISSING: ast,ir
843+
indirect_sink(fp); // $ ir MISSING: ast
844844
return 0;
845845
}

0 commit comments

Comments
 (0)