File tree Expand file tree Collapse file tree 2 files changed +36
-5
lines changed
cpp/ql/test/query-tests/Security/CWE/CWE-570 Expand file tree Collapse file tree 2 files changed +36
-5
lines changed Original file line number Diff line number Diff line change 13
13
| test.cpp:92:5:92:31 | new[] | This allocation cannot throw. $@ is unnecessary. | test.cpp:97:36:98:3 | { ... } | This catch block |
14
14
| test.cpp:93:15:93:41 | new[] | This allocation cannot throw. $@ is unnecessary. | test.cpp:97:36:98:3 | { ... } | This catch block |
15
15
| test.cpp:96:10:96:36 | new[] | This allocation cannot throw. $@ is unnecessary. | test.cpp:97:36:98:3 | { ... } | This catch block |
16
- | test.cpp:151:9:151:24 | new | This allocation cannot throw. $@ is unnecessary. | test.cpp:152:15:152:18 | { ... } | This catch block |
17
- | test.cpp:199:15:199:35 | new | This allocation cannot throw. $@ is unnecessary. | test.cpp:201:16:201:19 | { ... } | This catch block |
18
- | test.cpp:212:14:212:34 | new | This allocation cannot throw. $@ is unnecessary. | test.cpp:213:34:213:36 | { ... } | This catch block |
19
- | test.cpp:246:17:246:31 | new[] | This allocation cannot return null. $@ is unnecessary. | test.cpp:247:8:247:12 | ! ... | This check |
16
+ | test.cpp:160:9:160:24 | new | This allocation cannot throw. $@ is unnecessary. | test.cpp:161:15:161:18 | { ... } | This catch block |
17
+ | test.cpp:178:12:178:25 | new | This allocation cannot throw. $@ is unnecessary. | test.cpp:179:17:181:3 | { ... } | This catch block |
18
+ | test.cpp:229:15:229:35 | new | This allocation cannot throw. $@ is unnecessary. | test.cpp:231:16:231:19 | { ... } | This catch block |
19
+ | test.cpp:242:14:242:34 | new | This allocation cannot throw. $@ is unnecessary. | test.cpp:243:34:243:36 | { ... } | This catch block |
20
+ | test.cpp:276:17:276:31 | new[] | This allocation cannot return null. $@ is unnecessary. | test.cpp:277:8:277:12 | ! ... | This check |
Original file line number Diff line number Diff line change @@ -136,6 +136,8 @@ void good_new_handles_nullptr() {
136
136
return ; // GOOD
137
137
}
138
138
139
+ // ---
140
+
139
141
void * operator new (std::size_t count, void *) noexcept ;
140
142
void * operator new [](std::size_t count, void *) noexcept ;
141
143
@@ -146,18 +148,46 @@ struct Foo {
146
148
operator bool ();
147
149
};
148
150
151
+ struct Bar {
152
+ Bar ();
153
+
154
+ operator bool ();
155
+ };
156
+
149
157
void bad_placement_new_with_exception_handling () {
150
158
char buffer[1024 ];
151
- try { new (buffer) Foo; } // BAD
159
+
160
+ try { new (buffer) Foo; } // BAD (placement new should not fail)
152
161
catch (...) { }
153
162
}
154
163
155
164
void good_placement_new_with_exception_handling () {
156
165
char buffer[1024 ];
166
+
157
167
try { new (buffer) Foo (42 ); } // GOOD: Foo constructor might throw
158
168
catch (...) { }
169
+
170
+ try { new (buffer) Bar; } // GOOD: Bar constructor might throw
171
+ catch (...) { }
159
172
}
160
173
174
+ template <typename F> F *test_template_platement_new () {
175
+ char buffer[1024 ];
176
+
177
+ try {
178
+ return new (buffer) F; // GOOD: `F` constructor might throw (when `F` is `Foo`) [FALSE POSITIVE]
179
+ } catch (...) {
180
+ return 0 ;
181
+ }
182
+ }
183
+
184
+ void test_template_platement_new_caller () {
185
+ test_template_platement_new<Foo>();
186
+ test_template_platement_new<Bar>();
187
+ }
188
+
189
+ // ---
190
+
161
191
int unknown_value_without_exceptions () noexcept ;
162
192
163
193
void may_throw () {
You can’t perform that action at this time.
0 commit comments