Skip to content

Commit fbaf398

Browse files
committed
C++: QLDoc FileWrite and OutputWrite.
1 parent e01f050 commit fbaf398

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

cpp/ql/src/semmle/code/cpp/security/FileWrite.qll

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1+
/**
2+
* Provides classes for modelling writing of data to files through various standard mechanisms such as `fprintf`, `fwrite` and `operator<<`.
3+
*/
4+
15
import cpp
26

37
/**
4-
* A function call that writes to a file
8+
* A function call that writes to a file.
59
*/
610
class FileWrite extends Expr {
711
FileWrite() { fileWrite(this, _, _) }
812

13+
/**
14+
* Gets a source expression of this write.
15+
*/
916
Expr getASource() { fileWrite(this, result, _) }
1017

18+
/**
19+
* Gets the expression for the object being written to.
20+
*/
1121
Expr getDest() { fileWrite(this, _, result) }
1222
}
1323

@@ -44,17 +54,17 @@ class BasicOStreamCall extends FunctionCall {
4454
*/
4555
abstract class ChainedOutputCall extends BasicOStreamCall {
4656
/**
47-
* The source expression of this output.
57+
* Gets the source expression of this output.
4858
*/
4959
abstract Expr getSource();
5060

5161
/**
52-
* The immediate destination expression of this output.
62+
* Gets the immediate destination expression of this output.
5363
*/
5464
abstract Expr getDest();
5565

5666
/**
57-
* The destination at the far left-hand end of the output chain.
67+
* Gets the destination at the far left-hand end of the output chain.
5868
*/
5969
Expr getEndDest() {
6070
// recurse into the destination
@@ -108,7 +118,7 @@ class WriteFunctionCall extends ChainedOutputCall {
108118
}
109119

110120
/**
111-
* Whether the function call is a call to &lt;&lt; that eventually starts at the given file stream.
121+
* Whether the function call is a call to `operator<<` or a similar function, that eventually starts at the given file stream.
112122
*/
113123
private predicate fileStreamChain(ChainedOutputCall out, Expr source, Expr dest) {
114124
source = out.getSource() and

cpp/ql/src/semmle/code/cpp/security/OutputWrite.qll

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1+
/**
2+
* Provides classes for modelling output to standard output / standard error through various mechanisms such as `printf`, `puts` and `operator<<`.
3+
*/
4+
15
import cpp
26
import FileWrite
37

48
/**
5-
* A function call that writes to standard output or standard error
9+
* A function call that writes to standard output or standard error.
610
*/
711
class OutputWrite extends Expr {
812
OutputWrite() { outputWrite(this, _) }
913

14+
/**
15+
* Gets a source expression for this output.
16+
*/
1017
Expr getASource() { outputWrite(this, result) }
1118
}
1219

@@ -49,7 +56,7 @@ private predicate outputFile(Expr e) {
4956
}
5057

5158
/**
52-
* is the function call a write to standard output or standard error from 'source'
59+
* Holds if the function call is a write to standard output or standard error from 'source'.
5360
*/
5461
private predicate outputWrite(Expr write, Expr source) {
5562
exists(Function f, int arg |

0 commit comments

Comments
 (0)