Skip to content

Commit af09dd8

Browse files
committed
C++: Fixes to gets models.
1 parent 036e149 commit af09dd8

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

cpp/ql/lib/semmle/code/cpp/models/implementations/Gets.qll

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ private class FgetsFunction extends DataFlowFunction, TaintFunction, ArrayFuncti
5050
override predicate hasRemoteFlowSource(FunctionOutput output, string description) {
5151
output.isParameterDeref(0) and
5252
description = "String read by " + this.getName()
53+
or
54+
output.isReturnValue() and
55+
description = "String read by " + this.getName()
5356
}
5457

5558
override predicate hasArrayWithVariableSize(int bufParam, int countParam) {
@@ -78,8 +81,7 @@ private class GetsFunction extends DataFlowFunction, TaintFunction, ArrayFunctio
7881
}
7982

8083
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
81-
input.isParameter(2) and
82-
output.isParameterDeref(0)
84+
none()
8385
}
8486

8587
override predicate parameterNeverEscapes(int index) { none() }
@@ -101,6 +103,9 @@ private class GetsFunction extends DataFlowFunction, TaintFunction, ArrayFunctio
101103
override predicate hasLocalFlowSource(FunctionOutput output, string description) {
102104
output.isParameterDeref(0) and
103105
description = "String read by " + this.getName()
106+
or
107+
output.isReturnValue() and
108+
description = "String read by " + this.getName()
104109
}
105110

106111
override predicate hasArrayWithUnknownSize(int bufParam) { bufParam = 0 }
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
edges
22
| test.cpp:54:17:54:20 | argv | test.cpp:58:25:58:29 | input |
33
nodes
4+
| test2.cpp:110:3:110:6 | call to gets | semmle.label | call to gets |
45
| test.cpp:54:17:54:20 | argv | semmle.label | argv |
56
| test.cpp:58:25:58:29 | input | semmle.label | input |
67
subpaths
78
#select
9+
| test2.cpp:110:3:110:6 | call to gets | test2.cpp:110:3:110:6 | call to gets | test2.cpp:110:3:110:6 | call to gets | This write into buffer 'password' may contain unencrypted data from $@ | test2.cpp:110:3:110:6 | call to gets | user input (String read by gets) |
810
| test.cpp:58:3:58:9 | call to sprintf | test.cpp:54:17:54:20 | argv | test.cpp:58:25:58:29 | input | This write into buffer 'passwd' may contain unencrypted data from $@ | test.cpp:54:17:54:20 | argv | user input (a command-line argument) |

0 commit comments

Comments
 (0)