Skip to content

Commit f6a9d30

Browse files
committed
A18-1-4: Address compiler compatibility issue
libc++ defines release inline in the header, which causes extraneous paths to be reported by CodeQL. Adjust to summarize and exclude.
1 parent 14e4193 commit f6a9d30

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

cpp/autosar/src/rules/A18-1-4/PointerToAnElementOfAnArrayPassedToASmartPointer.ql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,24 @@ class SingleObjectSmartPointerArrayConstructionConfig extends TaintTracking::Con
5050
)
5151
)
5252
}
53+
54+
override predicate isAdditionalTaintStep(DataFlow::Node source, DataFlow::Node sink) {
55+
exists(AutosarUniquePointer sp, FunctionCall fc |
56+
fc = sp.getAReleaseCall() and
57+
source.asExpr() = fc.getQualifier() and
58+
sink.asExpr() = fc
59+
)
60+
}
61+
62+
override predicate isSanitizerIn(DataFlow::Node node) {
63+
// Exclude flow into header files outside the source archive which are summarized by the
64+
// additional taint steps above.
65+
exists(AutosarUniquePointer sp |
66+
sp.getAReleaseCall().getTarget() = node.asExpr().(ThisExpr).getEnclosingFunction()
67+
|
68+
not exists(node.getLocation().getFile().getRelativePath())
69+
)
70+
}
5371
}
5472

5573
from

cpp/common/src/codingstandards/cpp/SmartPointers.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ abstract class AutosarSmartPointer extends Class {
7070

7171
class AutosarUniquePointer extends AutosarSmartPointer {
7272
AutosarUniquePointer() { this.hasQualifiedName("std", "unique_ptr") }
73+
74+
FunctionCall getAReleaseCall() {
75+
result.getTarget().hasName("release") and
76+
result.getQualifier().getType().stripType() = this
77+
}
7378
}
7479

7580
class AutosarSharedPointer extends AutosarSmartPointer {

cpp/common/test/includes/standard-library/memory.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,20 @@ template <class T, class D> class unique_ptr<T[], D> {
5757
pointer get() const noexcept;
5858
explicit operator bool() const noexcept;
5959

60-
pointer release() noexcept;
60+
pointer release() noexcept {
61+
pointer __p = get();
62+
_M_p = pointer();
63+
return __p;
64+
}
6165
void reset(pointer p = pointer()) noexcept;
6266
void reset(nullptr_t) noexcept;
6367
template <class U> void reset(U) = delete;
6468
void swap(unique_ptr &u) noexcept;
6569
unique_ptr(const unique_ptr &) = delete;
6670
unique_ptr &operator=(const unique_ptr &) = delete;
71+
72+
private:
73+
pointer _M_p;
6774
};
6875

6976
template <class T, class... Args> unique_ptr<T> make_unique(Args &&...args);

0 commit comments

Comments
 (0)