Skip to content

Commit 29a294f

Browse files
committed
C++: Bind the columns inside the predicate instead of relying on 'bindingset's. The repeated inlining caused by 'bindiingset's created some #shared predicates with repeated regex matching.
1 parent dfdc2a6 commit 29a294f

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

cpp/ql/lib/semmle/code/cpp/dataflow/ExternalFlow.qll

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ private string getTypeNameWithoutFunctionTemplates(Function f, int n, int remain
656656
* Normalize the `n`'th parameter of `f` by replacing template names
657657
* with `class:N` (where `N` is the index of the template).
658658
*/
659+
pragma[nomagic]
659660
private string getTypeNameWithoutClassTemplates(Function f, int n, int remaining) {
660661
// If there is a declaring type then we start by expanding the function templates
661662
exists(Class template |
@@ -727,6 +728,7 @@ private string getSignatureWithoutClassTemplateNames(
727728
* - The `remaining` number of template arguments in `partiallyNormalizedSignature`
728729
* with their index in `nameArgs`.
729730
*/
731+
pragma[nomagic]
730732
private string getSignatureWithoutFunctionTemplateNames(
731733
string partiallyNormalizedSignature, string typeArgs, string nameArgs, int remaining
732734
) {
@@ -770,6 +772,7 @@ private string getSignatureWithoutFunctionTemplateNames(
770772
* ```
771773
* In this case, `normalizedSignature` will be `"(const func:0 &,int,class:1,class:0 *)"`.
772774
*/
775+
pragma[nomagic]
773776
private predicate elementSpecWithArguments(
774777
string signature, string type, string name, string normalizedSignature, string typeArgs,
775778
string nameArgs
@@ -795,23 +798,26 @@ private string getSignatureParameterName(string signature, string type, string n
795798
* If `subtypes` is `true` then the result may be an override of the function
796799
* identified by the components.
797800
*/
798-
bindingset[type, name]
801+
pragma[nomagic]
799802
private Function getFunction(string namespace, string type, boolean subtypes, string name) {
800-
funcHasQualifiedName(result, namespace, name) and
801-
subtypes = false and
802-
type = ""
803-
or
804-
exists(Class namedClass, Class classWithMethod |
805-
hasClassAndName(classWithMethod, result, name) and
806-
classHasQualifiedName(namedClass, namespace, type)
807-
|
808-
// member declared in the named type or a subtype of it
809-
subtypes = true and
810-
classWithMethod = namedClass.getADerivedClass*()
811-
or
812-
// member declared directly in the named type
803+
elementSpec(namespace, type, subtypes, name, _, _) and
804+
(
805+
funcHasQualifiedName(result, namespace, name) and
813806
subtypes = false and
814-
classWithMethod = namedClass
807+
type = ""
808+
or
809+
exists(Class namedClass, Class classWithMethod |
810+
hasClassAndName(classWithMethod, result, name) and
811+
classHasQualifiedName(namedClass, namespace, type)
812+
|
813+
// member declared in the named type or a subtype of it
814+
subtypes = true and
815+
classWithMethod = namedClass.getADerivedClass*()
816+
or
817+
// member declared directly in the named type
818+
subtypes = false and
819+
classWithMethod = namedClass
820+
)
815821
)
816822
}
817823

@@ -838,6 +844,7 @@ private Function getFunction(string namespace, string type, boolean subtypes, st
838844
* is `func:n` then the signature name is compared with the `n`'th name
839845
* in `name`.
840846
*/
847+
pragma[nomagic]
841848
private predicate signatureMatches(
842849
Function func, string namespace, string signature, string type, string name, int i
843850
) {
@@ -912,6 +919,7 @@ private predicate parseParens(string s, string betweenParens) { s = "(" + betwee
912919
* - `signatureWithoutParens` equals `signature`, but with the surrounding
913920
* parentheses removed.
914921
*/
922+
pragma[nomagic]
915923
private predicate elementSpecWithArguments0(
916924
string signature, string type, string name, string signatureWithoutParens, string typeArgs,
917925
string nameArgs

cpp/ql/test/library-tests/dataflow/taint-tests/test_mad-signatures.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ signatureMatches
135135
| stl.h:678:33:678:38 | format | std | (format_string,Args &&) | | format<Args> | 0 |
136136
| stl.h:678:33:678:38 | format | std | (format_string,Args &&) | | format<Args> | 1 |
137137
| stl.h:678:33:678:38 | format | std | (format_string,Args &&) | | format<Args> | 1 |
138-
| taint.cpp:735:7:735:12 | malloc | | (size_t) | | malloc | 0 |
139138
| taint.cpp:847:5:847:11 | toupper | | (int) | | toupper | 0 |
140139
| taint.cpp:848:5:848:11 | tolower | | (int) | | tolower | 0 |
141140
getSignatureParameterName

0 commit comments

Comments
 (0)