Skip to content

Commit ee35bfb

Browse files
committed
C++: Do not use isReturnValue in getenv, gets, and fgets models
1 parent e438671 commit ee35bfb

File tree

5 files changed

+1
-50
lines changed

5 files changed

+1
-50
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ class Getenv extends LocalFlowSourceFunction {
1616
}
1717

1818
override predicate hasLocalFlowSource(FunctionOutput output, string description) {
19-
(
20-
output.isReturnValueDeref() or
21-
output.isReturnValue()
22-
) and
19+
output.isReturnValueDeref() and
2320
description = "an environment variable"
2421
}
2522
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ private class FgetsFunction extends DataFlowFunction, TaintFunction, ArrayFuncti
5151
override predicate hasRemoteFlowSource(FunctionOutput output, string description) {
5252
(
5353
output.isParameterDeref(0) or
54-
output.isReturnValue() or
5554
output.isReturnValueDeref()
5655
) and
5756
description = "string read by " + this.getName()
@@ -102,7 +101,6 @@ private class GetsFunction extends DataFlowFunction, ArrayFunction, AliasFunctio
102101
override predicate hasLocalFlowSource(FunctionOutput output, string description) {
103102
(
104103
output.isParameterDeref(0) or
105-
output.isReturnValue() or
106104
output.isReturnValueDeref()
107105
) and
108106
description = "string read by " + this.getName()

cpp/ql/test/query-tests/Security/CWE/CWE-078/semmle/ExecTainted/ExecTainted.expected

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,15 @@ edges
1414
| test.cpp:91:9:91:16 | fread output argument | test.cpp:93:17:93:24 | filename indirection |
1515
| test.cpp:93:11:93:14 | strncat output argument | test.cpp:94:45:94:48 | path indirection |
1616
| test.cpp:93:17:93:24 | filename indirection | test.cpp:93:11:93:14 | strncat output argument |
17-
| test.cpp:106:20:106:38 | call to getenv | test.cpp:107:33:107:36 | path indirection |
1817
| test.cpp:106:20:106:38 | call to getenv indirection | test.cpp:107:33:107:36 | path indirection |
1918
| test.cpp:107:31:107:31 | call to operator+ | test.cpp:108:18:108:22 | call to c_str indirection |
2019
| test.cpp:107:33:107:36 | path indirection | test.cpp:107:31:107:31 | call to operator+ |
21-
| test.cpp:113:20:113:38 | call to getenv | test.cpp:114:19:114:22 | path indirection |
2220
| test.cpp:113:20:113:38 | call to getenv indirection | test.cpp:114:19:114:22 | path indirection |
2321
| test.cpp:114:10:114:23 | call to operator+ | test.cpp:114:25:114:29 | call to c_str indirection |
2422
| test.cpp:114:10:114:23 | call to operator+ | test.cpp:114:25:114:29 | call to c_str indirection |
2523
| test.cpp:114:17:114:17 | call to operator+ | test.cpp:114:10:114:23 | call to operator+ |
2624
| test.cpp:114:19:114:22 | path indirection | test.cpp:114:10:114:23 | call to operator+ |
2725
| test.cpp:114:19:114:22 | path indirection | test.cpp:114:17:114:17 | call to operator+ |
28-
| test.cpp:119:20:119:38 | call to getenv | test.cpp:120:19:120:22 | path indirection |
2926
| test.cpp:119:20:119:38 | call to getenv indirection | test.cpp:120:19:120:22 | path indirection |
3027
| test.cpp:120:17:120:17 | call to operator+ | test.cpp:120:10:120:30 | call to data indirection |
3128
| test.cpp:120:19:120:22 | path indirection | test.cpp:120:17:120:17 | call to operator+ |
@@ -89,20 +86,17 @@ nodes
8986
| test.cpp:93:11:93:14 | strncat output argument | semmle.label | strncat output argument |
9087
| test.cpp:93:17:93:24 | filename indirection | semmle.label | filename indirection |
9188
| test.cpp:94:45:94:48 | path indirection | semmle.label | path indirection |
92-
| test.cpp:106:20:106:38 | call to getenv | semmle.label | call to getenv |
9389
| test.cpp:106:20:106:38 | call to getenv indirection | semmle.label | call to getenv indirection |
9490
| test.cpp:107:31:107:31 | call to operator+ | semmle.label | call to operator+ |
9591
| test.cpp:107:33:107:36 | path indirection | semmle.label | path indirection |
9692
| test.cpp:108:18:108:22 | call to c_str indirection | semmle.label | call to c_str indirection |
97-
| test.cpp:113:20:113:38 | call to getenv | semmle.label | call to getenv |
9893
| test.cpp:113:20:113:38 | call to getenv indirection | semmle.label | call to getenv indirection |
9994
| test.cpp:114:10:114:23 | call to operator+ | semmle.label | call to operator+ |
10095
| test.cpp:114:10:114:23 | call to operator+ | semmle.label | call to operator+ |
10196
| test.cpp:114:17:114:17 | call to operator+ | semmle.label | call to operator+ |
10297
| test.cpp:114:19:114:22 | path indirection | semmle.label | path indirection |
10398
| test.cpp:114:25:114:29 | call to c_str indirection | semmle.label | call to c_str indirection |
10499
| test.cpp:114:25:114:29 | call to c_str indirection | semmle.label | call to c_str indirection |
105-
| test.cpp:119:20:119:38 | call to getenv | semmle.label | call to getenv |
106100
| test.cpp:119:20:119:38 | call to getenv indirection | semmle.label | call to getenv indirection |
107101
| test.cpp:120:10:120:30 | call to data indirection | semmle.label | call to data indirection |
108102
| test.cpp:120:17:120:17 | call to operator+ | semmle.label | call to operator+ |
@@ -156,13 +150,9 @@ subpaths
156150
| test.cpp:65:10:65:16 | command | test.cpp:62:9:62:16 | fread output argument | test.cpp:65:10:65:16 | command indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to system(string). | test.cpp:62:9:62:16 | fread output argument | user input (string read by fread) | test.cpp:64:11:64:17 | strncat output argument | strncat output argument |
157151
| test.cpp:85:32:85:38 | command | test.cpp:82:9:82:16 | fread output argument | test.cpp:85:32:85:38 | command indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to execl. | test.cpp:82:9:82:16 | fread output argument | user input (string read by fread) | test.cpp:84:11:84:17 | strncat output argument | strncat output argument |
158152
| test.cpp:94:45:94:48 | path | test.cpp:91:9:91:16 | fread output argument | test.cpp:94:45:94:48 | path indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to execl. | test.cpp:91:9:91:16 | fread output argument | user input (string read by fread) | test.cpp:93:11:93:14 | strncat output argument | strncat output argument |
159-
| test.cpp:108:18:108:22 | call to c_str | test.cpp:106:20:106:38 | call to getenv | test.cpp:108:18:108:22 | call to c_str indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to system(string). | test.cpp:106:20:106:38 | call to getenv | user input (an environment variable) | test.cpp:107:31:107:31 | call to operator+ | call to operator+ |
160153
| test.cpp:108:18:108:22 | call to c_str | test.cpp:106:20:106:38 | call to getenv indirection | test.cpp:108:18:108:22 | call to c_str indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to system(string). | test.cpp:106:20:106:38 | call to getenv indirection | user input (an environment variable) | test.cpp:107:31:107:31 | call to operator+ | call to operator+ |
161-
| test.cpp:114:25:114:29 | call to c_str | test.cpp:113:20:113:38 | call to getenv | test.cpp:114:25:114:29 | call to c_str indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to system(string). | test.cpp:113:20:113:38 | call to getenv | user input (an environment variable) | test.cpp:114:10:114:23 | call to operator+ | call to operator+ |
162-
| test.cpp:114:25:114:29 | call to c_str | test.cpp:113:20:113:38 | call to getenv | test.cpp:114:25:114:29 | call to c_str indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to system(string). | test.cpp:113:20:113:38 | call to getenv | user input (an environment variable) | test.cpp:114:17:114:17 | call to operator+ | call to operator+ |
163154
| test.cpp:114:25:114:29 | call to c_str | test.cpp:113:20:113:38 | call to getenv indirection | test.cpp:114:25:114:29 | call to c_str indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to system(string). | test.cpp:113:20:113:38 | call to getenv indirection | user input (an environment variable) | test.cpp:114:10:114:23 | call to operator+ | call to operator+ |
164155
| test.cpp:114:25:114:29 | call to c_str | test.cpp:113:20:113:38 | call to getenv indirection | test.cpp:114:25:114:29 | call to c_str indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to system(string). | test.cpp:113:20:113:38 | call to getenv indirection | user input (an environment variable) | test.cpp:114:17:114:17 | call to operator+ | call to operator+ |
165-
| test.cpp:120:25:120:28 | call to data | test.cpp:119:20:119:38 | call to getenv | test.cpp:120:10:120:30 | call to data indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to system(string). | test.cpp:119:20:119:38 | call to getenv | user input (an environment variable) | test.cpp:120:17:120:17 | call to operator+ | call to operator+ |
166156
| test.cpp:120:25:120:28 | call to data | test.cpp:119:20:119:38 | call to getenv indirection | test.cpp:120:10:120:30 | call to data indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to system(string). | test.cpp:119:20:119:38 | call to getenv indirection | user input (an environment variable) | test.cpp:120:17:120:17 | call to operator+ | call to operator+ |
167157
| test.cpp:143:10:143:16 | command | test.cpp:140:9:140:11 | fread output argument | test.cpp:143:10:143:16 | command indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to system(string). | test.cpp:140:9:140:11 | fread output argument | user input (string read by fread) | test.cpp:142:11:142:17 | sprintf output argument | sprintf output argument |
168158
| test.cpp:183:32:183:38 | command | test.cpp:174:9:174:16 | fread output argument | test.cpp:183:32:183:38 | command indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to execl. | test.cpp:174:9:174:16 | fread output argument | user input (string read by fread) | test.cpp:177:13:177:17 | strncat output argument | strncat output argument |

0 commit comments

Comments
 (0)