|
1 | 1 | import cpp
|
2 | 2 | import Expr
|
| 3 | +private import semmle.code.cpp.security.FileWrite |
3 | 4 |
|
4 | 5 | /**
|
5 | 6 | * any assignment operator that also reads from the access
|
@@ -264,3 +265,51 @@ class UserOverloadedOperator extends Function {
|
264 | 265 | not this.isCompilerGenerated()
|
265 | 266 | }
|
266 | 267 | }
|
| 268 | + |
| 269 | +/** |
| 270 | + * A `std::basic_istream` class, or something that can be used |
| 271 | + * as one. Based on the BasicOStreamClass. |
| 272 | + */ |
| 273 | +private class BasicIStreamClass extends Type { |
| 274 | + BasicIStreamClass() { |
| 275 | + this.(Class).getName().matches("basic\\_istream%") |
| 276 | + or |
| 277 | + this.getUnspecifiedType() instanceof BasicIStreamClass |
| 278 | + or |
| 279 | + this.(Class).getABaseClass() instanceof BasicIStreamClass |
| 280 | + or |
| 281 | + this.(ReferenceType).getBaseType() instanceof BasicIStreamClass |
| 282 | + } |
| 283 | +} |
| 284 | + |
| 285 | +/** An implementation of a stream insertion operator. */ |
| 286 | +class StreamInsertionOperator extends Function { |
| 287 | + StreamInsertionOperator() { |
| 288 | + this.hasName("operator<<") and |
| 289 | + ( |
| 290 | + if this.isMember() |
| 291 | + then this.getNumberOfParameters() = 1 |
| 292 | + else ( |
| 293 | + this.getNumberOfParameters() = 2 and |
| 294 | + this.getParameter(0).getType() instanceof BasicOStreamClass |
| 295 | + ) |
| 296 | + ) and |
| 297 | + this.getType() instanceof BasicOStreamClass |
| 298 | + } |
| 299 | +} |
| 300 | + |
| 301 | +/** An implementation of a stream extraction operator. */ |
| 302 | +class StreamExtractionOperator extends Function { |
| 303 | + StreamExtractionOperator() { |
| 304 | + this.hasName("operator>>") and |
| 305 | + ( |
| 306 | + if this.isMember() |
| 307 | + then this.getNumberOfParameters() = 1 |
| 308 | + else ( |
| 309 | + this.getNumberOfParameters() = 2 and |
| 310 | + this.getParameter(0).getType() instanceof BasicIStreamClass |
| 311 | + ) |
| 312 | + ) and |
| 313 | + this.getType() instanceof BasicIStreamClass |
| 314 | + } |
| 315 | +} |
0 commit comments