Skip to content

Commit 30d9c6b

Browse files
authored
Merge pull request github#3776 from geoffw0/qldoc
C++: QLDoc ObjectiveC.qll, BufferWrite.qll, FileWrite.qll, OutputWrite.qll
2 parents b402352 + fbaf398 commit 30d9c6b

File tree

4 files changed

+49
-7
lines changed

4 files changed

+49
-7
lines changed

cpp/ql/src/semmle/code/cpp/ObjectiveC.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* DEPRECATED: Objective-C is no longer supported.
3+
*/
4+
15
import semmle.code.cpp.Class
26
private import semmle.code.cpp.internal.ResolveClass
37

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ class StrCopyBW extends BufferWriteCall {
146146
)
147147
}
148148

149+
/**
150+
* Gets the index of the parameter that is the maximum size of the copy (in characters).
151+
*/
149152
int getParamSize() {
150153
exists(TopLevelFunction fn, string name |
151154
fn = getTarget() and
@@ -161,6 +164,9 @@ class StrCopyBW extends BufferWriteCall {
161164
)
162165
}
163166

167+
/**
168+
* Gets the index of the parameter that is the source of the copy.
169+
*/
164170
int getParamSrc() {
165171
exists(TopLevelFunction fn, string name |
166172
fn = getTarget() and
@@ -194,8 +200,14 @@ class StrCopyBW extends BufferWriteCall {
194200
class StrCatBW extends BufferWriteCall {
195201
StrCatBW() { exists(TopLevelFunction fn | fn = getTarget() and fn instanceof StrcatFunction) }
196202

203+
/**
204+
* Gets the index of the parameter that is the maximum size of the copy (in characters).
205+
*/
197206
int getParamSize() { if exists(getArgument(2)) then result = 2 else none() }
198207

208+
/**
209+
* Gets the index of the parameter that is the source of the copy.
210+
*/
199211
int getParamSrc() { result = 1 }
200212

201213
override Type getBufferType() {
@@ -349,6 +361,9 @@ class SnprintfBW extends BufferWriteCall {
349361
)
350362
}
351363

364+
/**
365+
* Gets the index of the parameter that is the size of the destination (in characters).
366+
*/
352367
int getParamSize() { result = 1 }
353368

354369
override Type getBufferType() {
@@ -399,6 +414,9 @@ class GetsBW extends BufferWriteCall {
399414
)
400415
}
401416

417+
/**
418+
* Gets the index of the parameter that is the maximum number of characters to be read.
419+
*/
402420
int getParamSize() { if exists(getArgument(1)) then result = 1 else none() }
403421

404422
override Type getBufferType() { result = this.getTarget().getParameter(0).getUnspecifiedType() }
@@ -434,6 +452,9 @@ class ScanfBW extends BufferWrite {
434452
)
435453
}
436454

455+
/**
456+
* Gets the index of the parameter that is the first format argument.
457+
*/
437458
int getParamArgs() {
438459
exists(FunctionCall fc |
439460
this = fc.getArgument(_) and

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)