Skip to content

Commit 685b840

Browse files
MaskRayAlexisPerry
authored andcommitted
__asan_register_elf_globals: properly check the "no instrumented global variable" case
On ELF platforms, the instrumentation registers global variables using `__asan_register_elf_globals` for the default `UseGlobalsGC` case. If all instrumented global variables in a module are discarded by linker GC, we will have `start == stop`. Normally `start == 0`, but `start != 0` is possible with a linker script retaining `asan_globals`. The called `__asan_register_globals` would access out-of-bounds `globals[n-1]`, though there is likely no runtime failure. Pull Request: llvm#96529
1 parent 972a170 commit 685b840

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

compiler-rt/lib/asan/asan_globals.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,8 @@ void __asan_unregister_image_globals(uptr *flag) {
344344
}
345345

346346
void __asan_register_elf_globals(uptr *flag, void *start, void *stop) {
347-
if (*flag) return;
348-
if (!start) return;
347+
if (*flag || start == stop)
348+
return;
349349
CHECK_EQ(0, ((uptr)stop - (uptr)start) % sizeof(__asan_global));
350350
__asan_global *globals_start = (__asan_global*)start;
351351
__asan_global *globals_stop = (__asan_global*)stop;
@@ -354,8 +354,8 @@ void __asan_register_elf_globals(uptr *flag, void *start, void *stop) {
354354
}
355355

356356
void __asan_unregister_elf_globals(uptr *flag, void *start, void *stop) {
357-
if (!*flag) return;
358-
if (!start) return;
357+
if (!*flag || start == stop)
358+
return;
359359
CHECK_EQ(0, ((uptr)stop - (uptr)start) % sizeof(__asan_global));
360360
__asan_global *globals_start = (__asan_global*)start;
361361
__asan_global *globals_stop = (__asan_global*)stop;

0 commit comments

Comments
 (0)