mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-02 18:58:15 +00:00
9a954c6935
The 'counted_by' attribute is used on flexible array members. The argument for the attribute is the name of the field member in the same structure holding the count of elements in the flexible array. This information can be used to improve the results of the array bound sanitizer and the '__builtin_dynamic_object_size' builtin. This example specifies the that the flexible array member 'array' has the number of elements allocated for it in 'count': struct bar; struct foo { size_t count; /* ... */ struct bar *array[] __attribute__((counted_by(count))); }; This establishes a relationship between 'array' and 'count', specifically that 'p->array' must have *at least* 'p->count' number of elements available. It's the user's responsibility to ensure that this relationship is maintained through changes to the structure. In the following, the allocated array erroneously has fewer elements than what's specified by 'p->count'. This would result in an out-of-bounds access not not being detected: struct foo *p; void foo_alloc(size_t count) { p = malloc(MAX(sizeof(struct foo), offsetof(struct foo, array[0]) + count * sizeof(struct bar *))); p->count = count + 42; } The next example updates 'p->count', breaking the relationship requirement that 'p->array' must have at least 'p->count' number of elements available: struct foo *p; void foo_alloc(size_t count) { p = malloc(MAX(sizeof(struct foo), offsetof(struct foo, array[0]) + count * sizeof(struct bar *))); p->count = count + 42; } void use_foo(int index) { p->count += 42; p->array[index] = 0; /* The sanitizer cannot properly check this access */ } Reviewed By: nickdesaulniers, aaron.ballman Differential Revision: https://reviews.llvm.org/D148381 |
||
---|---|---|
.. | ||
AnalysisBasedWarnings.cpp | ||
CMakeLists.txt | ||
CodeCompleteConsumer.cpp | ||
CoroutineStmtBuilder.h | ||
DeclSpec.cpp | ||
DelayedDiagnostic.cpp | ||
HLSLExternalSemaSource.cpp | ||
IdentifierResolver.cpp | ||
JumpDiagnostics.cpp | ||
MultiplexExternalSemaSource.cpp | ||
OpenCLBuiltins.td | ||
ParsedAttr.cpp | ||
Scope.cpp | ||
ScopeInfo.cpp | ||
Sema.cpp | ||
SemaAccess.cpp | ||
SemaAttr.cpp | ||
SemaAvailability.cpp | ||
SemaCast.cpp | ||
SemaChecking.cpp | ||
SemaCodeComplete.cpp | ||
SemaConcept.cpp | ||
SemaConsumer.cpp | ||
SemaCoroutine.cpp | ||
SemaCUDA.cpp | ||
SemaCXXScopeSpec.cpp | ||
SemaDecl.cpp | ||
SemaDeclAttr.cpp | ||
SemaDeclCXX.cpp | ||
SemaDeclObjC.cpp | ||
SemaExceptionSpec.cpp | ||
SemaExpr.cpp | ||
SemaExprCXX.cpp | ||
SemaExprMember.cpp | ||
SemaExprObjC.cpp | ||
SemaFixItUtils.cpp | ||
SemaHLSL.cpp | ||
SemaInit.cpp | ||
SemaLambda.cpp | ||
SemaLookup.cpp | ||
SemaModule.cpp | ||
SemaObjCProperty.cpp | ||
SemaOpenMP.cpp | ||
SemaOverload.cpp | ||
SemaPseudoObject.cpp | ||
SemaRISCVVectorLookup.cpp | ||
SemaStmt.cpp | ||
SemaStmtAsm.cpp | ||
SemaStmtAttr.cpp | ||
SemaSYCL.cpp | ||
SemaTemplate.cpp | ||
SemaTemplateDeduction.cpp | ||
SemaTemplateInstantiate.cpp | ||
SemaTemplateInstantiateDecl.cpp | ||
SemaTemplateVariadic.cpp | ||
SemaType.cpp | ||
TreeTransform.h | ||
TypeLocBuilder.cpp | ||
TypeLocBuilder.h | ||
UsedDeclVisitor.h |