Skip to content

Commit b9bc216

Browse files
authored
Merge pull request #2808 from rdmarsh2/function-with-wrappers
C++: fix cartesian product in FunctionWithWrapper
2 parents 405850e + d672f8f commit b9bc216

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

cpp/ql/src/semmle/code/cpp/security/FunctionWithWrappers.qll

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,22 @@ abstract class FunctionWithWrappers extends Function {
9494
)
9595
}
9696

97+
/**
98+
* Whether 'func' is a (possibly nested) wrapper function that feeds a parameter at the given index
99+
* through to an interesting parameter of 'this' function.
100+
*
101+
* The 'cause' gives the name of 'this' interesting function and its relevant parameter
102+
* at the end of the call chain.
103+
*
104+
* If there is more than one possible 'cause', a unique one is picked (by lexicographic order).
105+
*/
106+
pragma[nomagic]
107+
private string wrapperFunctionAnyDepthUnique(Function func, int paramIndex) {
108+
result =
109+
toCause(func, paramIndex) + ", which ends up calling " +
110+
min(string targetCause | this.wrapperFunctionAnyDepth(func, paramIndex, targetCause))
111+
}
112+
97113
/**
98114
* Whether 'func' is a (possibly nested) wrapper function that feeds a parameter at the given index
99115
* through to an interesting parameter of 'this' function.
@@ -114,13 +130,7 @@ abstract class FunctionWithWrappers extends Function {
114130
)
115131
or
116132
not this.wrapperFunctionLimitedDepth(func, paramIndex, _, _) and
117-
cause =
118-
min(string targetCause, string possibleCause |
119-
this.wrapperFunctionAnyDepth(func, paramIndex, targetCause) and
120-
possibleCause = toCause(func, paramIndex) + ", which ends up calling " + targetCause
121-
|
122-
possibleCause
123-
)
133+
cause = wrapperFunctionAnyDepthUnique(func, paramIndex)
124134
}
125135

126136
/**

0 commit comments

Comments
 (0)