@@ -39,6 +39,12 @@ class StringConcatenation extends Call {
39
39
result = this .getAnArgument ( ) and
40
40
// addresses odd behavior with overloaded operators
41
41
// 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.
42
48
not result instanceof Call and
43
49
// Limit the result type to string
44
50
(
@@ -62,11 +68,7 @@ class StringConcatenation extends Call {
62
68
or
63
69
exists ( int n |
64
70
result = this .getArgument ( n ) and
65
- n >=
66
- this .( FormattingFunctionCall )
67
- .getTarget ( )
68
- .( FormattingFunction )
69
- .getFirstFormatArgumentIndex ( )
71
+ n >= this .( FormattingFunctionCall ) .getTarget ( ) .getFirstFormatArgumentIndex ( )
70
72
)
71
73
)
72
74
)
@@ -82,17 +84,15 @@ class StringConcatenation extends Call {
82
84
this .getArgument ( this .getTarget ( ) .( StrcatFunction ) .getParamDest ( ) )
83
85
or
84
86
// Hardcoding it is also the return
85
- [ result .asExpr ( ) , result . asIndirectExpr ( ) ] = this .( Call )
87
+ result .asExpr ( ) = this .( Call )
86
88
else
87
89
if this .getTarget ( ) instanceof StrlcatFunction
88
90
then (
89
- [ result .asExpr ( ) , result . asIndirectExpr ( ) ] =
91
+ result .asDefiningArgument ( ) =
90
92
this .getArgument ( this .getTarget ( ) .( StrlcatFunction ) .getParamDest ( ) )
91
93
) else
92
94
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 )
97
97
}
98
98
}
0 commit comments