Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f688470

Browse files
committed
C++: Since isConstructedFrom only holds for templates we need to explicitly handle the case where the function (or class) is not a template.
1 parent bf36f00 commit f688470

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,18 +434,30 @@ private predicate elementSpec(
434434
summaryModel(namespace, type, subtypes, name, signature, ext, _, _, _, _, _)
435435
}
436436

437+
private predicate isClassConstructedFrom(Class c, Class templateClass) {
438+
c.isConstructedFrom(templateClass)
439+
or
440+
not any(Class c_).isConstructedFrom(templateClass) and c = templateClass
441+
}
442+
443+
private predicate isFunctionConstructedFrom(Function f, Function templateFunc) {
444+
f.isConstructedFrom(templateFunc)
445+
or
446+
not any(Function f_).isConstructedFrom(templateFunc) and f = templateFunc
447+
}
448+
437449
/** Gets the fully templated version of `f`. */
438450
private Function getFullyTemplatedFunction(Function f) {
439451
not f.isFromUninstantiatedTemplate(_) and
440452
(
441453
exists(Class c, Class templateClass, int i |
442-
c.isConstructedFrom(templateClass) and
454+
isClassConstructedFrom(c, templateClass) and
443455
f = c.getAMember(i) and
444456
result = templateClass.getCanonicalMember(i)
445457
)
446458
or
447459
not exists(f.getDeclaringType()) and
448-
f.isConstructedFrom(result)
460+
isFunctionConstructedFrom(f, result)
449461
)
450462
}
451463

@@ -489,7 +501,7 @@ private string getTypeNameWithoutFunctionTemplates(Function f, int n, int remain
489501
private string getTypeNameWithoutClassTemplates(Function f, int n, int remaining) {
490502
// If there is a declaring type then we start by expanding the function templates
491503
exists(Class template |
492-
f.getDeclaringType().isConstructedFrom(template) and
504+
isClassConstructedFrom(f.getDeclaringType(), template) and
493505
remaining = template.getNumberOfTemplateArguments() and
494506
result = getTypeNameWithoutFunctionTemplates(f, n, 0)
495507
)
@@ -501,7 +513,7 @@ private string getTypeNameWithoutClassTemplates(Function f, int n, int remaining
501513
or
502514
exists(string mid, TemplateParameter tp, Class template |
503515
mid = getTypeNameWithoutClassTemplates(f, n, remaining + 1) and
504-
f.getDeclaringType().isConstructedFrom(template) and
516+
isClassConstructedFrom(f.getDeclaringType(), template) and
505517
tp = template.getTemplateArgument(remaining) and
506518
result = mid.replaceAll(tp.getName(), "class:" + remaining.toString())
507519
)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ void test__U_STRINGorID() {
7575
{
7676
UINT x = source<UINT>();
7777
_U_STRINGorID u(x);
78-
sink(u.m_lpstr); // $ MISSING: ir
78+
sink(u.m_lpstr); // $ ir
7979
}
8080

8181
{
8282
LPCTSTR y = indirect_source<const char>();
8383
_U_STRINGorID u(y);
84-
sink(u.m_lpstr); // $ MISSING: ir
84+
sink(u.m_lpstr); // $ ir
8585
}
8686
}

0 commit comments

Comments
 (0)