Skip to content

Commit d86fea5

Browse files
authored
Merge pull request #18114 from MathiasVP/actually-check-func-name-in-mad
C++: Actually check function names in MaD
2 parents df2e2e5 + e42c745 commit d86fea5

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

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

+7-8
Original file line numberDiff line numberDiff line change
@@ -793,28 +793,27 @@ private Element interpretElement0(
793793
) {
794794
(
795795
// Non-member functions
796-
elementSpec(namespace, type, subtypes, name, signature, _) and
796+
funcHasQualifiedName(result, namespace, name) and
797797
subtypes = false and
798798
type = "" and
799799
(
800800
elementSpecMatchesSignature(result, namespace, type, subtypes, name, signature)
801801
or
802802
signature = "" and
803-
elementSpec(namespace, type, subtypes, name, "", _) and
804-
funcHasQualifiedName(result, namespace, name)
803+
elementSpec(namespace, type, subtypes, name, signature, _)
805804
)
806805
or
807806
// Member functions
808807
exists(Class namedClass, Class classWithMethod |
808+
hasClassAndName(classWithMethod, result, name) and
809+
classHasQualifiedName(namedClass, namespace, type)
810+
|
809811
(
810-
elementSpecMatchesSignature(result, namespace, type, subtypes, name, signature) and
811-
hasClassAndName(classWithMethod, result, name)
812+
elementSpecMatchesSignature(result, namespace, type, subtypes, name, signature)
812813
or
813814
signature = "" and
814-
elementSpec(namespace, type, subtypes, name, "", _) and
815-
hasClassAndName(classWithMethod, result, name)
815+
elementSpec(namespace, type, subtypes, name, "", _)
816816
) and
817-
classHasQualifiedName(namedClass, namespace, type) and
818817
(
819818
// member declared in the named type or a subtype of it
820819
subtypes = true and

cpp/ql/test/library-tests/dataflow/taint-tests/format.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,10 @@ void test_format() {
164164

165165
auto s2 = std::format(string::source());
166166
sink(s2); // $ ir MISSING: ast
167+
}
168+
169+
void test(std::format_string s) {
170+
int x = source();
171+
int y = std::same_signature_as_format_but_different_name(s, x);
172+
sink(y); // clean
167173
}

cpp/ql/test/library-tests/dataflow/taint-tests/localTaint.expected

+3
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,9 @@ WARNING: module 'TaintTracking' has been deprecated and may be removed in future
451451
| format.cpp:162:24:162:27 | {} | format.cpp:162:24:162:27 | call to basic_format_string | TAINT |
452452
| format.cpp:165:13:165:23 | call to format | format.cpp:166:8:166:9 | s2 | |
453453
| format.cpp:165:25:165:38 | call to source | format.cpp:165:25:165:40 | call to basic_format_string | TAINT |
454+
| format.cpp:169:30:169:30 | s | format.cpp:171:60:171:60 | s | |
455+
| format.cpp:170:11:170:16 | call to source | format.cpp:171:63:171:63 | x | |
456+
| format.cpp:171:11:171:58 | call to same_signature_as_format_but_different_name | format.cpp:172:8:172:8 | y | |
454457
| map.cpp:21:28:21:28 | call to pair | map.cpp:23:2:23:2 | a | |
455458
| map.cpp:21:28:21:28 | call to pair | map.cpp:24:7:24:7 | a | |
456459
| map.cpp:21:28:21:28 | call to pair | map.cpp:25:7:25:7 | a | |

cpp/ql/test/library-tests/dataflow/taint-tests/stl.h

+5
Original file line numberDiff line numberDiff line change
@@ -676,4 +676,9 @@ namespace std {
676676
using format_string = basic_format_string<char>; // simplified from `char, std::type_identity_t<Args>...`
677677

678678
template<class... Args> string format( format_string fmt, Args&&... args );
679+
680+
// This function has the same signature as `format`, but a different name. It should NOT be able to use
681+
// the model for `format`.
682+
template <typename... Args>
683+
int same_signature_as_format_but_different_name(format_string, Args &&...args);
679684
}

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

+4
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ signatureMatches
265265
| stl.h:678:33:678:38 | format | (format_string,Args &&) | | format<Args> | 0 |
266266
| stl.h:678:33:678:38 | format | (format_string,Args &&) | | format<Args> | 1 |
267267
| stl.h:678:33:678:38 | format | (format_string,Args &&) | | format<Args> | 1 |
268+
| stl.h:683:6:683:48 | same_signature_as_format_but_different_name | (format_string,Args &&) | | format<Args> | 0 |
269+
| stl.h:683:6:683:48 | same_signature_as_format_but_different_name | (format_string,Args &&) | | format<Args> | 1 |
268270
getSignatureParameterName
269271
| (InputIt,InputIt) | deque | assign<InputIt> | 0 | func:0 |
270272
| (InputIt,InputIt) | deque | assign<InputIt> | 1 | func:0 |
@@ -729,6 +731,8 @@ getParameterTypeName
729731
| stl.h:678:33:678:38 | format | 0 | format_string |
730732
| stl.h:678:33:678:38 | format | 1 | func:0 && |
731733
| stl.h:678:33:678:38 | format | 1 | func:0 && |
734+
| stl.h:683:6:683:48 | same_signature_as_format_but_different_name | 0 | format_string |
735+
| stl.h:683:6:683:48 | same_signature_as_format_but_different_name | 1 | func:0 && |
732736
| stringstream.cpp:18:6:18:9 | sink | 0 | const basic_ostream> & |
733737
| stringstream.cpp:21:6:21:9 | sink | 0 | const basic_istream> & |
734738
| stringstream.cpp:24:6:24:9 | sink | 0 | const basic_iostream> & |

0 commit comments

Comments
 (0)