diff options
Diffstat (limited to 'contrib/llvm-project/compiler-rt/lib/asan/asan_descriptions.cpp')
-rw-r--r-- | contrib/llvm-project/compiler-rt/lib/asan/asan_descriptions.cpp | 94 |
1 files changed, 50 insertions, 44 deletions
diff --git a/contrib/llvm-project/compiler-rt/lib/asan/asan_descriptions.cpp b/contrib/llvm-project/compiler-rt/lib/asan/asan_descriptions.cpp index 153c874a4e77..ef6f3e0a096f 100644 --- a/contrib/llvm-project/compiler-rt/lib/asan/asan_descriptions.cpp +++ b/contrib/llvm-project/compiler-rt/lib/asan/asan_descriptions.cpp @@ -44,19 +44,19 @@ void DescribeThread(AsanThreadContext *context) { CHECK(context); asanThreadRegistry().CheckLocked(); // No need to announce the main thread. - if (context->tid == 0 || context->announced) { + if (context->tid == kMainTid || context->announced) { return; } context->announced = true; - InternalScopedString str(1024); - str.append("Thread %s", AsanThreadIdAndName(context).c_str()); + InternalScopedString str; + str.AppendF("Thread %s", AsanThreadIdAndName(context).c_str()); if (context->parent_tid == kInvalidTid) { - str.append(" created by unknown thread\n"); + str.Append(" created by unknown thread\n"); Printf("%s", str.data()); return; } - str.append(" created by %s here:\n", - AsanThreadIdAndName(context->parent_tid).c_str()); + str.AppendF(" created by %s here:\n", + AsanThreadIdAndName(context->parent_tid).c_str()); Printf("%s", str.data()); StackDepotGet(context->stack_id).Print(); // Recursively described parent thread if needed. @@ -77,7 +77,6 @@ static bool GetShadowKind(uptr addr, ShadowKind *shadow_kind) { } else if (AddrIsInLowShadow(addr)) { *shadow_kind = kShadowKindLow; } else { - CHECK(0 && "Address is not in memory and not in shadow?"); return false; } return true; @@ -126,30 +125,30 @@ static void GetAccessToHeapChunkInformation(ChunkAccess *descr, static void PrintHeapChunkAccess(uptr addr, const ChunkAccess &descr) { Decorator d; - InternalScopedString str(4096); - str.append("%s", d.Location()); + InternalScopedString str; + str.Append(d.Location()); switch (descr.access_type) { case kAccessTypeLeft: - str.append("%p is located %zd bytes to the left of", - (void *)descr.bad_addr, descr.offset); + str.AppendF("%p is located %zd bytes before", (void *)descr.bad_addr, + descr.offset); break; case kAccessTypeRight: - str.append("%p is located %zd bytes to the right of", - (void *)descr.bad_addr, descr.offset); + str.AppendF("%p is located %zd bytes after", (void *)descr.bad_addr, + descr.offset); break; case kAccessTypeInside: - str.append("%p is located %zd bytes inside of", (void *)descr.bad_addr, - descr.offset); + str.AppendF("%p is located %zd bytes inside of", (void *)descr.bad_addr, + descr.offset); break; case kAccessTypeUnknown: - str.append( + str.AppendF( "%p is located somewhere around (this is AddressSanitizer bug!)", (void *)descr.bad_addr); } - str.append(" %zu-byte region [%p,%p)\n", descr.chunk_size, - (void *)descr.chunk_begin, - (void *)(descr.chunk_begin + descr.chunk_size)); - str.append("%s", d.Default()); + str.AppendF(" %zu-byte region [%p,%p)\n", descr.chunk_size, + (void *)descr.chunk_begin, + (void *)(descr.chunk_begin + descr.chunk_size)); + str.Append(d.Default()); Printf("%s", str.data()); } @@ -243,25 +242,25 @@ static void PrintAccessAndVarIntersection(const StackVarDescr &var, uptr addr, else if (addr >= prev_var_end && addr - prev_var_end >= var.beg - addr_end) pos_descr = "underflows"; } - InternalScopedString str(1024); - str.append(" [%zd, %zd)", var.beg, var_end); + InternalScopedString str; + str.AppendF(" [%zd, %zd)", var.beg, var_end); // Render variable name. - str.append(" '"); + str.AppendF(" '"); for (uptr i = 0; i < var.name_len; ++i) { - str.append("%c", var.name_pos[i]); + str.AppendF("%c", var.name_pos[i]); } - str.append("'"); + str.AppendF("'"); if (var.line > 0) { - str.append(" (line %d)", var.line); + str.AppendF(" (line %zd)", var.line); } if (pos_descr) { Decorator d; // FIXME: we may want to also print the size of the access here, // but in case of accesses generated by memset it may be confusing. - str.append("%s <== Memory access at offset %zd %s this variable%s\n", - d.Location(), addr, pos_descr, d.Default()); + str.AppendF("%s <== Memory access at offset %zd %s this variable%s\n", + d.Location(), addr, pos_descr, d.Default()); } else { - str.append("\n"); + str.AppendF("\n"); } Printf("%s", str.data()); } @@ -276,25 +275,25 @@ bool DescribeAddressIfStack(uptr addr, uptr access_size) { // Global descriptions static void DescribeAddressRelativeToGlobal(uptr addr, uptr access_size, const __asan_global &g) { - InternalScopedString str(4096); + InternalScopedString str; Decorator d; - str.append("%s", d.Location()); + str.Append(d.Location()); if (addr < g.beg) { - str.append("%p is located %zd bytes to the left", (void *)addr, - g.beg - addr); + str.AppendF("%p is located %zd bytes before", (void *)addr, g.beg - addr); } else if (addr + access_size > g.beg + g.size) { if (addr < g.beg + g.size) addr = g.beg + g.size; - str.append("%p is located %zd bytes to the right", (void *)addr, - addr - (g.beg + g.size)); + str.AppendF("%p is located %zd bytes after", (void *)addr, + addr - (g.beg + g.size)); } else { // Can it happen? - str.append("%p is located %zd bytes inside", (void *)addr, addr - g.beg); + str.AppendF("%p is located %zd bytes inside of", (void *)addr, + addr - g.beg); } - str.append(" of global variable '%s' defined in '", - MaybeDemangleGlobalName(g.name)); - PrintGlobalLocation(&str, g); - str.append("' (0x%zx) of size %zu\n", g.beg, g.size); - str.append("%s", d.Default()); + str.AppendF(" global variable '%s' defined in '", + MaybeDemangleGlobalName(g.name)); + PrintGlobalLocation(&str, g, /*print_module_name=*/false); + str.AppendF("' (0x%zx) of size %zu\n", g.beg, g.size); + str.Append(d.Default()); PrintGlobalNameIfASCII(&str, g); Printf("%s", str.data()); } @@ -319,7 +318,8 @@ bool DescribeAddressIfGlobal(uptr addr, uptr access_size, } void ShadowAddressDescription::Print() const { - Printf("Address %p is located in the %s area.\n", addr, ShadowNames[kind]); + Printf("Address %p is located in the %s area.\n", (void *)addr, + ShadowNames[kind]); } void GlobalAddressDescription::Print(const char *bug_type) const { @@ -357,7 +357,7 @@ bool GlobalAddressDescription::PointsInsideTheSameVariable( void StackAddressDescription::Print() const { Decorator d; Printf("%s", d.Location()); - Printf("Address %p is located in stack of thread %s", addr, + Printf("Address %p is located in stack of thread %s", (void *)addr, AsanThreadIdAndName(tid).c_str()); if (!frame_descr) { @@ -464,7 +464,13 @@ AddressDescription::AddressDescription(uptr addr, uptr access_size, return; } data.kind = kAddressKindWild; - addr = 0; + data.wild.addr = addr; + data.wild.access_size = access_size; +} + +void WildAddressDescription::Print() const { + Printf("Address %p is a wild pointer inside of access range of size %p.\n", + (void *)addr, (void *)access_size); } void PrintAddressDescription(uptr addr, uptr access_size, |