@@ -36,20 +36,20 @@ class StdString extends Class {
3636 * Holds if `e` is a direct or indirect reference to a locally
3737 * allocated `std::string`.
3838 */
39- predicate refToStdString ( Expr e , ConstructorCall source ) {
39+ predicate refToStdString ( DataFlow :: Node node , ConstructorCall source ) {
4040 exists ( StdString stdstring |
4141 stdstring .getAMemberFunction ( ) = source .getTarget ( ) and
4242 not exists ( LocalVariable v |
4343 source = v .getInitializer ( ) .getExpr ( ) and
4444 v .isStatic ( )
4545 ) and
46- e = source
46+ node . asExpr ( ) = source
4747 )
4848 or
4949 // Indirect use.
50- exists ( Expr prev |
50+ exists ( DataFlow :: Node prev |
5151 refToStdString ( prev , source ) and
52- DataFlow:: localFlowStep ( DataFlow :: exprNode ( prev ) , DataFlow :: exprNode ( e ) )
52+ DataFlow:: localFlowStep ( prev , node )
5353 )
5454}
5555
@@ -74,29 +74,30 @@ predicate flowFunction(Function fcn, int argIndex) {
7474 * Holds if `e` is a direct or indirect reference to the result of calling
7575 * `c_str` on a locally allocated `std::string`.
7676 */
77- predicate refToCStr ( Expr e , ConstructorCall source ) {
78- exists ( MemberFunction f , FunctionCall call |
77+ predicate refToCStr ( DataFlow :: Node node , ConstructorCall source ) {
78+ exists ( MemberFunction f , FunctionCall call , DataFlow :: Node qualifier |
7979 f .getName ( ) = "c_str" and
80- call = e and
80+ call = node . asExpr ( ) and
8181 call .getTarget ( ) = f and
82- refToStdString ( call .getQualifier ( ) , source )
82+ qualifier .asIndirectArgument ( ) = call .getQualifier ( ) and
83+ refToStdString ( qualifier , source )
8384 )
8485 or
8586 // Indirect use.
86- exists ( Expr prev |
87+ exists ( DataFlow :: Node prev |
8788 refToCStr ( prev , source ) and
88- DataFlow:: localFlowStep ( DataFlow :: exprNode ( prev ) , DataFlow :: exprNode ( e ) )
89+ DataFlow:: localFlowStep ( prev , node )
8990 )
9091 or
9192 // Some functions, such as `JNIEnv::NewStringUTF()` (from Java's JNI)
9293 // embed return a structure containing a reference to the C-style string.
9394 exists ( Function f , int argIndex |
9495 flowFunction ( f , argIndex ) and
95- f = e .( Call ) .getTarget ( ) and
96- refToCStr ( e . ( Call ) .getArgument ( argIndex ) , source )
96+ f = node . asExpr ( ) .( Call ) .getTarget ( ) and
97+ refToCStr ( DataFlow :: exprNode ( node . asExpr ( ) . ( Call ) .getArgument ( argIndex ) ) , source )
9798 )
9899}
99100
100101from ReturnStmt r , ConstructorCall source
101- where refToCStr ( r .getExpr ( ) , source )
102+ where refToCStr ( DataFlow :: exprNode ( r .getExpr ( ) ) , source )
102103select r , "Return value may contain a dangling pointer to $@." , source , "this local std::string"
0 commit comments