@@ -39,6 +39,12 @@ class StringConcatenation extends Call {
3939 result = this .getAnArgument ( ) and
4040 // addresses odd behavior with overloaded operators
4141 // i.e., "call to operator+" appearing as an operand
42+ // occurs in cases like `string s = s1 + s2 + s3`, which is represented as
43+ // `string s = (s1.operator+(s2)).operator+(s3);`
44+ // By limiting to non-calls we get the leaf operands (the variables or raw strings)
45+ // also, by not enuemrating allowed types (variables and strings) we avoid issues
46+ // with missed corner cases or extensions/changes to CodeQL in the future which might
47+ // invalidate that approach.
4248 not result instanceof Call and
4349 // Limit the result type to string
4450 (
@@ -62,11 +68,7 @@ class StringConcatenation extends Call {
6268 or
6369 exists ( int n |
6470 result = this .getArgument ( n ) and
65- n >=
66- this .( FormattingFunctionCall )
67- .getTarget ( )
68- .( FormattingFunction )
69- .getFirstFormatArgumentIndex ( )
71+ n >= this .( FormattingFunctionCall ) .getTarget ( ) .getFirstFormatArgumentIndex ( )
7072 )
7173 )
7274 )
@@ -82,17 +84,15 @@ class StringConcatenation extends Call {
8284 this .getArgument ( this .getTarget ( ) .( StrcatFunction ) .getParamDest ( ) )
8385 or
8486 // Hardcoding it is also the return
85- [ result .asExpr ( ) , result . asIndirectExpr ( ) ] = this .( Call )
87+ result .asExpr ( ) = this .( Call )
8688 else
8789 if this .getTarget ( ) instanceof StrlcatFunction
8890 then (
89- [ result .asExpr ( ) , result . asIndirectExpr ( ) ] =
91+ result .asDefiningArgument ( ) =
9092 this .getArgument ( this .getTarget ( ) .( StrlcatFunction ) .getParamDest ( ) )
9193 ) else
9294 if this instanceof FormattingFunctionCall
93- then
94- [ result .asExpr ( ) , result .asIndirectExpr ( ) ] =
95- this .( FormattingFunctionCall ) .getOutputArgument ( _)
96- else [ result .asExpr ( ) , result .asIndirectExpr ( ) ] = this .( Call )
95+ then result .asDefiningArgument ( ) = this .( FormattingFunctionCall ) .getOutputArgument ( _)
96+ else result .asExpr ( ) = this .( Call )
9797 }
9898}
0 commit comments