Skip to content

Commit 4fb29c4

Browse files
authored
Merge branch 'main' into jcogs33/java/add-apache-ant-path-inj-sinks
2 parents ff9093f + 05b0a3f commit 4fb29c4

File tree

316 files changed

+10600
-7848
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

316 files changed

+10600
-7848
lines changed

cpp/ql/lib/ext/std.format.model.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/cpp-all
4+
extensible: summaryModel
5+
data: # namespace, type, subtypes, name, signature, ext, input, output, kind, provenance
6+
- ["std", "", False, "format<Args>", "(format_string,Args &&)", "", "Argument[0]", "ReturnValue", "taint", "manual"]
7+
- ["std", "", False, "format<Args>", "(format_string,Args &&)", "", "Argument[*1]", "ReturnValue", "taint", "manual"]
8+
- ["std", "", False, "format<Args>", "(format_string,Args &&)", "", "Argument[*2]", "ReturnValue", "taint", "manual"]
9+
- ["std", "", False, "format<Args>", "(format_string,Args &&)", "", "Argument[*3]", "ReturnValue", "taint", "manual"]
10+
- ["std", "", False, "format<Args>", "(format_string,Args &&)", "", "Argument[*4]", "ReturnValue", "taint", "manual"]
11+
- ["std", "", False, "format<Args>", "(format_string,Args &&)", "", "Argument[*5]", "ReturnValue", "taint", "manual"]
12+
- ["std", "", False, "format<Args>", "(format_string,Args &&)", "", "Argument[*6]", "ReturnValue", "taint", "manual"]
13+
- ["std", "", False, "format<Args>", "(format_string,Args &&)", "", "Argument[*7]", "ReturnValue", "taint", "manual"]
14+
- ["std", "", False, "format<Args>", "(format_string,Args &&)", "", "Argument[*8]", "ReturnValue", "taint", "manual"]

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

Lines changed: 41 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -435,12 +435,17 @@ private predicate elementSpec(
435435
}
436436

437437
/** Gets the fully templated version of `f`. */
438-
private Function getFullyTemplatedMemberFunction(Function f) {
438+
private Function getFullyTemplatedFunction(Function f) {
439439
not f.isFromUninstantiatedTemplate(_) and
440-
exists(Class c, Class templateClass, int i |
441-
c.isConstructedFrom(templateClass) and
442-
f = c.getAMember(i) and
443-
result = templateClass.getCanonicalMember(i)
440+
(
441+
exists(Class c, Class templateClass, int i |
442+
c.isConstructedFrom(templateClass) and
443+
f = c.getAMember(i) and
444+
result = templateClass.getCanonicalMember(i)
445+
)
446+
or
447+
not exists(f.getDeclaringType()) and
448+
f.isConstructedFrom(result)
444449
)
445450
}
446451

@@ -464,14 +469,14 @@ string getParameterTypeWithoutTemplateArguments(Function f, int n) {
464469
*/
465470
private string getTypeNameWithoutFunctionTemplates(Function f, int n, int remaining) {
466471
exists(Function templateFunction |
467-
templateFunction = getFullyTemplatedMemberFunction(f) and
472+
templateFunction = getFullyTemplatedFunction(f) and
468473
remaining = templateFunction.getNumberOfTemplateArguments() and
469474
result = getParameterTypeWithoutTemplateArguments(templateFunction, n)
470475
)
471476
or
472477
exists(string mid, TemplateParameter tp, Function templateFunction |
473478
mid = getTypeNameWithoutFunctionTemplates(f, n, remaining + 1) and
474-
templateFunction = getFullyTemplatedMemberFunction(f) and
479+
templateFunction = getFullyTemplatedFunction(f) and
475480
tp = templateFunction.getTemplateArgument(remaining) and
476481
result = mid.replaceAll(tp.getName(), "func:" + remaining.toString())
477482
)
@@ -482,12 +487,18 @@ private string getTypeNameWithoutFunctionTemplates(Function f, int n, int remain
482487
* with `class:N` (where `N` is the index of the template).
483488
*/
484489
private string getTypeNameWithoutClassTemplates(Function f, int n, int remaining) {
490+
// If there is a declaring type then we start by expanding the function templates
485491
exists(Class template |
486492
f.getDeclaringType().isConstructedFrom(template) and
487493
remaining = template.getNumberOfTemplateArguments() and
488494
result = getTypeNameWithoutFunctionTemplates(f, n, 0)
489495
)
490496
or
497+
// If there is no declaring type we're done after expanding the function templates
498+
not exists(f.getDeclaringType()) and
499+
remaining = 0 and
500+
result = getTypeNameWithoutFunctionTemplates(f, n, 0)
501+
or
491502
exists(string mid, TemplateParameter tp, Class template |
492503
mid = getTypeNameWithoutClassTemplates(f, n, remaining + 1) and
493504
f.getDeclaringType().isConstructedFrom(template) and
@@ -570,38 +581,6 @@ private string getSignatureWithoutFunctionTemplateNames(
570581
)
571582
}
572583

573-
private string paramsStringPart(Function c, int i) {
574-
not c.isFromUninstantiatedTemplate(_) and
575-
(
576-
i = -1 and result = "(" and exists(c)
577-
or
578-
exists(int n, string p | getParameterTypeName(c, n) = p |
579-
i = 2 * n and result = p
580-
or
581-
i = 2 * n - 1 and result = "," and n != 0
582-
)
583-
or
584-
i = 2 * c.getNumberOfParameters() and result = ")"
585-
)
586-
}
587-
588-
/**
589-
* Gets a parenthesized string containing all parameter types of this callable, separated by a comma.
590-
*
591-
* Returns the empty string if the callable has no parameters.
592-
* Parameter types are represented by their type erasure.
593-
*/
594-
cached
595-
private string paramsString(Function c) {
596-
result = concat(int i | | paramsStringPart(c, i) order by i)
597-
}
598-
599-
bindingset[func]
600-
private predicate matchesSignature(Function func, string signature) {
601-
signature = "" or
602-
paramsString(func) = signature
603-
}
604-
605584
/**
606585
* Holds if `elementSpec(_, type, _, name, signature, _)` holds and
607586
* - `typeArgs` represents the named template parameters supplied to `type`, and
@@ -750,17 +729,17 @@ private predicate elementSpecWithArguments0(
750729

751730
/**
752731
* Holds if `elementSpec(namespace, type, subtypes, name, signature, _)` and
753-
* `method`'s signature matches `signature`.
732+
* `func`'s signature matches `signature`.
754733
*
755734
* `signature` may contain template parameter names that are bound by `type` and `name`.
756735
*/
757736
pragma[nomagic]
758737
private predicate elementSpecMatchesSignature(
759-
Function method, string namespace, string type, boolean subtypes, string name, string signature
738+
Function func, string namespace, string type, boolean subtypes, string name, string signature
760739
) {
761740
elementSpec(namespace, pragma[only_bind_into](type), subtypes, pragma[only_bind_into](name),
762741
pragma[only_bind_into](signature), _) and
763-
signatureMatches(method, signature, type, name, 0)
742+
signatureMatches(func, signature, type, name, 0)
764743
}
765744

766745
/**
@@ -776,13 +755,22 @@ private predicate hasClassAndName(Class classWithMethod, Function method, string
776755
)
777756
}
778757

758+
bindingset[name]
759+
pragma[inline_late]
760+
private predicate funcHasQualifiedName(Function func, string namespace, string name) {
761+
exists(string nameWithoutArgs |
762+
parseAngles(name, nameWithoutArgs, _, "") and
763+
func.hasQualifiedName(namespace, nameWithoutArgs)
764+
)
765+
}
766+
779767
/**
780768
* Holds if `namedClass` is in namespace `namespace` and has
781769
* name `type` (excluding any template parameters).
782770
*/
783771
bindingset[type, namespace]
784772
pragma[inline_late]
785-
private predicate hasQualifiedName(Class namedClass, string namespace, string type) {
773+
private predicate classHasQualifiedName(Class namedClass, string namespace, string type) {
786774
exists(string typeWithoutArgs |
787775
parseAngles(type, typeWithoutArgs, _, "") and
788776
namedClass.hasQualifiedName(namespace, typeWithoutArgs)
@@ -804,15 +792,16 @@ private Element interpretElement0(
804792
string namespace, string type, boolean subtypes, string name, string signature
805793
) {
806794
(
807-
elementSpec(namespace, type, subtypes, name, signature, _) and
808795
// Non-member functions
809-
exists(Function func |
810-
func.hasQualifiedName(namespace, name) and
811-
type = "" and
812-
matchesSignature(func, signature) and
813-
subtypes = false and
814-
not exists(func.getDeclaringType()) and
815-
result = func
796+
elementSpec(namespace, type, subtypes, name, signature, _) and
797+
subtypes = false and
798+
type = "" and
799+
(
800+
elementSpecMatchesSignature(result, namespace, type, subtypes, name, signature)
801+
or
802+
signature = "" and
803+
elementSpec(namespace, type, subtypes, name, "", _) and
804+
funcHasQualifiedName(result, namespace, name)
816805
)
817806
or
818807
// Member functions
@@ -825,7 +814,7 @@ private Element interpretElement0(
825814
elementSpec(namespace, type, subtypes, name, "", _) and
826815
hasClassAndName(classWithMethod, result, name)
827816
) and
828-
hasQualifiedName(namedClass, namespace, type) and
817+
classHasQualifiedName(namedClass, namespace, type) and
829818
(
830819
// member declared in the named type or a subtype of it
831820
subtypes = true and

cpp/ql/test/library-tests/attributes/routine_attributes/arguments.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
| declspec.cpp:4:23:4:43 | Use fatal() instead | declspec.cpp:4:59:4:62 | exit | declspec.cpp:4:12:4:21 | deprecated | Use fatal() instead |
22
| routine_attributes2.cpp:5:6:5:11 | hidden | routine_attributes2.cpp:5:13:5:21 | a_routine | routine_attributes2.cpp:5:6:5:11 | visibility | hidden |
3-
| routine_attributes2.cpp:5:6:5:11 | hidden | routine_attributes2.cpp:5:13:5:21 | a_routine | routine_attributes2.cpp:5:6:5:11 | visibility | hidden |
4-
| routine_attributes2.h:3:6:3:11 | hidden | routine_attributes2.cpp:5:13:5:21 | a_routine | routine_attributes2.h:3:6:3:11 | visibility | hidden |
53
| routine_attributes2.h:3:6:3:11 | hidden | routine_attributes2.cpp:5:13:5:21 | a_routine | routine_attributes2.h:3:6:3:11 | visibility | hidden |
64
| routine_attributes.c:3:53:3:59 | dummy | routine_attributes.c:3:12:3:24 | named_weakref | routine_attributes.c:3:44:3:50 | weakref | dummy |
75
| routine_attributes.c:4:62:4:68 | dummy | routine_attributes.c:4:12:4:26 | aliased_weakref | routine_attributes.c:4:55:4:59 | alias | dummy |

cpp/ql/test/library-tests/attributes/routine_attributes/routine_attributes.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
| header_export.cpp:18:6:18:16 | myFunction5 | header.h:10:2:10:10 | dllexport |
2020
| header_export.cpp:18:6:18:16 | myFunction5 | header.h:10:2:10:10 | dllimport |
2121
| routine_attributes2.cpp:5:13:5:21 | a_routine | routine_attributes2.cpp:5:6:5:11 | visibility |
22-
| routine_attributes2.cpp:5:13:5:21 | a_routine | routine_attributes2.cpp:5:6:5:11 | visibility |
23-
| routine_attributes2.cpp:5:13:5:21 | a_routine | routine_attributes2.h:3:6:3:11 | visibility |
2422
| routine_attributes2.cpp:5:13:5:21 | a_routine | routine_attributes2.h:3:6:3:11 | visibility |
2523
| routine_attributes.c:3:12:3:24 | named_weakref | routine_attributes.c:3:44:3:50 | weakref |
2624
| routine_attributes.c:4:12:4:26 | aliased_weakref | routine_attributes.c:4:46:4:52 | weakref |
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
| type_attributes2.cpp:5:14:5:20 | a_class | type_attributes2.cpp:5:7:5:12 | visibility | type_attributes2.cpp:5:7:5:12 | hidden |
22
| type_attributes2.cpp:5:14:5:20 | a_class | type_attributes2.h:3:7:3:12 | visibility | type_attributes2.h:3:7:3:12 | hidden |
3-
| type_attributes2.cpp:5:14:5:20 | a_class | type_attributes2.h:3:7:3:12 | visibility | type_attributes2.h:3:7:3:12 | hidden |
43
| type_attributes_ms.cpp:4:67:4:75 | IDispatch | type_attributes_ms.cpp:4:19:4:22 | uuid | type_attributes_ms.cpp:4:24:4:63 | {00020400-0000-0000-c000-000000000046} |
54
| type_attributes_ms.cpp:5:30:5:33 | Str1 | type_attributes_ms.cpp:5:12:5:16 | align | type_attributes_ms.cpp:5:18:5:19 | 32 |
65
| type_attributes_ms.cpp:6:55:6:62 | IUnknown | type_attributes_ms.cpp:6:2:6:2 | uuid | type_attributes_ms.cpp:6:2:6:2 | 00000000-0000-0000-c000-000000000046 |

cpp/ql/test/library-tests/attributes/type_attributes/type_attributes.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
| file://:0:0:0:0 | short __attribute((__may_alias__)) | type_attributes.c:25:30:25:42 | may_alias |
22
| type_attributes2.cpp:5:14:5:20 | a_class | type_attributes2.cpp:5:7:5:12 | visibility |
33
| type_attributes2.cpp:5:14:5:20 | a_class | type_attributes2.h:3:7:3:12 | visibility |
4-
| type_attributes2.cpp:5:14:5:20 | a_class | type_attributes2.h:3:7:3:12 | visibility |
54
| type_attributes.c:5:36:5:51 | my_packed_struct | type_attributes.c:5:23:5:32 | packed |
65
| type_attributes.c:10:54:10:54 | (unnamed class/struct/union) | type_attributes.c:10:30:10:50 | transparent_union |
76
| type_attributes.c:16:54:16:54 | (unnamed class/struct/union) | type_attributes.c:16:30:16:50 | transparent_union |

cpp/ql/test/library-tests/attributes/var_attributes/var_attributes.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
| ms_var_attributes.cpp:20:34:20:37 | pBuf | ms_var_attributes.cpp:20:12:20:12 | SAL_volatile |
88
| ms_var_attributes.h:5:22:5:27 | myInt3 | ms_var_attributes.h:5:1:5:9 | dllexport |
99
| var_attributes2.cpp:5:12:5:21 | a_variable | var_attributes2.cpp:5:5:5:10 | visibility |
10-
| var_attributes2.cpp:5:12:5:21 | a_variable | var_attributes2.cpp:5:5:5:10 | visibility |
11-
| var_attributes2.cpp:5:12:5:21 | a_variable | var_attributes2.h:3:12:3:17 | visibility |
1210
| var_attributes2.cpp:5:12:5:21 | a_variable | var_attributes2.h:3:12:3:17 | visibility |
1311
| var_attributes.c:1:12:1:19 | weak_var | var_attributes.c:1:36:1:39 | weak |
1412
| var_attributes.c:2:12:2:22 | weakref_var | var_attributes.c:2:39:2:45 | weakref |

cpp/ql/test/library-tests/dataflow/external-models/validatemodels.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
| Dubious signature "(const_iterator,size_type,const T &)" in summary model. |
1717
| Dubious signature "(deque &&)" in summary model. |
1818
| Dubious signature "(deque &&,const Allocator &)" in summary model. |
19+
| Dubious signature "(format_string,Args &&)" in summary model. |
1920
| Dubious signature "(forward_list &&)" in summary model. |
2021
| Dubious signature "(forward_list &&,const Allocator &)" in summary model. |
2122
| Dubious signature "(list &&)" in summary model. |

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
#include "stl.h"
22
typedef unsigned long size_t;
33
typedef struct {} FILE;
44

@@ -157,3 +157,11 @@ void test2()
157157
sink(s[strlen(s) - 1]); // $ ast,ir
158158
sink(ws + (wcslen(ws) / 2)); // $ ast,ir
159159
}
160+
161+
void test_format() {
162+
auto s = std::format("{}", string::source());
163+
sink(s); // $ ir MISSING: ast
164+
165+
auto s2 = std::format(string::source());
166+
sink(s2); // $ ir MISSING: ast
167+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,10 @@ WARNING: module 'TaintTracking' has been deprecated and may be removed in future
447447
| format.cpp:158:13:158:18 | call to wcslen | format.cpp:158:13:158:26 | ... / ... | TAINT |
448448
| format.cpp:158:13:158:26 | ... / ... | format.cpp:158:7:158:27 | ... + ... | TAINT |
449449
| format.cpp:158:26:158:26 | 2 | format.cpp:158:13:158:26 | ... / ... | TAINT |
450+
| format.cpp:162:12:162:22 | call to format | format.cpp:163:8:163:8 | s | |
451+
| format.cpp:162:24:162:27 | {} | format.cpp:162:24:162:27 | call to basic_format_string | TAINT |
452+
| format.cpp:165:13:165:23 | call to format | format.cpp:166:8:166:9 | s2 | |
453+
| format.cpp:165:25:165:38 | call to source | format.cpp:165:25:165:40 | call to basic_format_string | TAINT |
450454
| map.cpp:21:28:21:28 | call to pair | map.cpp:23:2:23:2 | a | |
451455
| map.cpp:21:28:21:28 | call to pair | map.cpp:24:7:24:7 | a | |
452456
| map.cpp:21:28:21:28 | call to pair | map.cpp:25:7:25:7 | a | |

0 commit comments

Comments
 (0)