@@ -296,10 +296,11 @@ class StdBasicOStream extends TemplateClass {
296296}
297297
298298/**
299- * The `std::ostream` function `operator<<` (defined as a member function).
299+ * The `std::ostream` functions `operator<<` (defined as a member function),
300+ * `put` and `write`.
300301 */
301302class StdOStreamOut extends DataFlowFunction , TaintFunction {
302- StdOStreamOut ( ) { this .hasQualifiedName ( "std" , "basic_ostream" , "operator<<" ) }
303+ StdOStreamOut ( ) { this .hasQualifiedName ( "std" , "basic_ostream" , [ "operator<<" , "put" , "write" ] ) }
303304
304305 override predicate hasDataFlow ( FunctionInput input , FunctionOutput output ) {
305306 // flow from qualifier to return value
@@ -308,14 +309,20 @@ class StdOStreamOut extends DataFlowFunction, TaintFunction {
308309 }
309310
310311 override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
311- // flow from parameter to qualifier
312+ // flow from first parameter (value or pointer) to qualifier
312313 input .isParameter ( 0 ) and
313314 output .isQualifierObject ( )
314315 or
315- // flow from parameter to return value
316+ input .isParameterDeref ( 0 ) and
317+ output .isQualifierObject ( )
318+ or
319+ // flow from first parameter (value or pointer) to return value
316320 input .isParameter ( 0 ) and
317321 output .isReturnValueDeref ( )
318322 or
323+ input .isParameterDeref ( 0 ) and
324+ output .isReturnValueDeref ( )
325+ or
319326 // reverse flow from returned reference to the qualifier
320327 input .isReturnValueDeref ( ) and
321328 output .isQualifierObject ( )
@@ -352,3 +359,43 @@ class StdOStreamOutNonMember extends DataFlowFunction, TaintFunction {
352359 output .isParameterDeref ( 0 )
353360 }
354361}
362+
363+ /**
364+ * Additional model for `std::stringstream` constructors that take a string
365+ * input parameter.
366+ */
367+ class StdStringStreamConstructor extends Constructor , TaintFunction {
368+ StdStringStreamConstructor ( ) {
369+ this .getDeclaringType ( ) .hasQualifiedName ( "std" , "basic_stringstream" )
370+ }
371+
372+ /**
373+ * Gets the index of a parameter to this function that is a string.
374+ */
375+ int getAStringParameterIndex ( ) {
376+ getParameter ( result ) .getType ( ) instanceof ReferenceType // `const std::basic_string &`
377+ }
378+
379+ override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
380+ // taint flow from any parameter of string type to the returned object
381+ input .isParameterDeref ( getAStringParameterIndex ( ) ) and
382+ output .isReturnValue ( ) // TODO: this should be `isQualifierObject` by our current definitions, but that flow is not yet supported.
383+ }
384+ }
385+
386+ /**
387+ * The `std::stringstream` function `str`.
388+ */
389+ class StdStringStreamStr extends TaintFunction {
390+ StdStringStreamStr ( ) { this .hasQualifiedName ( "std" , "basic_stringstream" , "str" ) }
391+
392+ override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
393+ // flow from qualifier to return value (if any)
394+ input .isQualifierObject ( ) and
395+ output .isReturnValue ( )
396+ or
397+ // flow from first parameter (if any) to qualifier
398+ input .isParameterDeref ( 0 ) and
399+ output .isQualifierObject ( )
400+ }
401+ }
0 commit comments