[PATCH] D36207: [compiler-rt] Check for empty buffer in Addr2LineProcess::ReadFromSymbolizer

David Lam via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 1 21:38:23 PDT 2017


david-y-lam created this revision.
Herald added subscribers: dberris, kubamracek.

This fixes a bug in the `ReadFromSymbolizer` method of the `Addr2LineProcess` class; if the input is too large, the returned buffer will be `null` and will consequently fail the `CHECK`. The proposed fix is to simply check if the buffer consists of only a null-terminator and return if so (in effect skipping that frame). I tested by running one of the unit tests both before and after my change.

Before:

  /data/users/davidlam/llvm/build 19:51$ ASAN_OPTIONS=allow_addr2line=true:external_symbolizer_path=/usr/local/bin/addr2line ASAN_SYMBOLIZER_PATH=../build/bin/llvm-symbolizer  ../build/projects/compiler-rt/test/sanitizer_common/asan-x86_64-Linux/Output/symbolize_stack.cc.tmp
      #0 0x4ffd23 in __sanitizer_print_stack_trace /data/users/davidlam/llvm/llvm/projects/compiler-rt/lib/asan/asan_stack.cc:38
  ==1180931==WARNING: Symbolizer buffer too small==1180931==AddressSanitizer CHECK failed: /data/users/davidlam/llvm/llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc:282 "((garbage)) != (0)(0x0, 0x0)

After:

  /data/users/davidlam/llvm/build 21:04$ ASAN_OPTIONS=allow_addr2line=true:external_symbolizer_path=/usr/local/bin/addr2line ../build/projects/compiler-rt/test/sanitizer_common/asan-x86_64-Linux/Output/symbolize_stack.cc.tmp
      #0 0x4ffd23 in __sanitizer_print_stack_trace /data/users/davidlam/llvm/llvm/projects/compiler-rt/lib/asan/asan_stack.cc:38
  ==2250158==WARNING: Symbolizer buffer too small
      #1 0x52dc84  (/data/users/davidlam/llvm/build/projects/compiler-rt/test/sanitizer_common/asan-x86_64-Linux/Output/symbolize_stack.cc.tmp+0x52dc84)
  ==2250158==WARNING: Symbolizer buffer too small
      #2 0x52d93f  (/data/users/davidlam/llvm/build/projects/compiler-rt/test/sanitizer_common/asan-x86_64-Linux/Output/symbolize_stack.cc.tmp+0x52d93f)
  ==2250158==WARNING: Symbolizer buffer too small
      #3 0x52d4ff  (/data/users/davidlam/llvm/build/projects/compiler-rt/test/sanitizer_common/asan-x86_64-Linux/Output/symbolize_stack.cc.tmp+0x52d4ff)
  ==2250158==WARNING: Symbolizer buffer too small
      #4 0x52d0bf  (/data/users/davidlam/llvm/build/projects/compiler-rt/test/sanitizer_common/asan-x86_64-Linux/Output/symbolize_stack.cc.tmp+0x52d0bf)
      #5 0x52cc7f in > >, std::allocator<std::vector<int, std::allocator<int> > > > > >, std::allocator<std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > > > > > > > >, std::allocator<std::vector<std::vector<std::vector<std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > >, std::allocator<std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > > > >, std::allocator<std::vector<std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > >, std::allocator<std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > > > > > >, std::allocator<std::vector<std::vector<std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > >, std::allocator<std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > > > >, std::allocator<std::vector<std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > >, std::allocator<std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > > > > > > > > > >, std::allocator<std::vector<std::vector<std::vector<std::vector<std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > >, std::allocator<std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > > > >, std::allocator<std::vector<std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > >, std::allocator<std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > > > > > >, std::allocator<std::vector<std::vector<std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > >, std::allocator<std::vector<std::
  ==2250158==WARNING: Symbolizer buffer too small
      #6 0x52c83f  (/data/users/davidlam/llvm/build/projects/compiler-rt/test/sanitizer_common/asan-x86_64-Linux/Output/symbolize_stack.cc.tmp+0x52c83f)
  ==2250158==WARNING: Symbolizer buffer too small
      #7 0x52c3ff  (/data/users/davidlam/llvm/build/projects/compiler-rt/test/sanitizer_common/asan-x86_64-Linux/Output/symbolize_stack.cc.tmp+0x52c3ff)
  ==2250158==WARNING: Symbolizer buffer too small
      #8 0x52bfbf  (/data/users/davidlam/llvm/build/projects/compiler-rt/test/sanitizer_common/asan-x86_64-Linux/Output/symbolize_stack.cc.tmp+0x52bfbf)
  ==2250158==WARNING: Symbolizer buffer too small
      #9 0x52bb7f  (/data/users/davidlam/llvm/build/projects/compiler-rt/test/sanitizer_common/asan-x86_64-Linux/Output/symbolize_stack.cc.tmp+0x52bb7f)
      #10 0x52b72f in t, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > > > >, std::allocator<std::vector<std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > >, std::allocator<std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > > > > > > > > >(std::vector<std::vector<std::vector<std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > >, std::allocator<std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > > > >, std::allocator<std::vector<std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > >, std::allocator<std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > > > > > >, std::allocator<std::vector<std::vector<std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > >, std::allocator<std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > > > >, std::allocator<std::vector<std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > >, std::allocator<std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > > > > > > > > const&) /data/users/davidlam/llvm/llvm/projects/compiler-rt/test/sanitizer_common/TestCases/symbolize_stack.cc:16
      #11 0x52b4ef in void A<7>::RecursiveTemplateFunction<std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > > >(std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > > const&) /data/users/davidlam/llvm/llvm/projects/compiler-rt/test/sanitizer_common/TestCases/symbolize_stack.cc:16
      #12 0x52b372 in void A<10>::RecursiveTemplateFunction<int>(int const&) /data/users/davidlam/llvm/llvm/projects/compiler-rt/test/sanitizer_common/TestCases/symbolize_stack.cc:16
      #13 0x7fbf7d47fb34 in __libc_start_main ??:?
      #14 0x41ad6b in main /data/users/davidlam/llvm/llvm/projects/compiler-rt/test/sanitizer_common/TestCases/symbolize_stack.cc:27


Repository:
  rL LLVM

https://reviews.llvm.org/D36207

Files:
  lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc
  lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc


Index: lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
===================================================================
--- lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
+++ lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
@@ -272,6 +272,10 @@
   bool ReadFromSymbolizer(char *buffer, uptr max_length) override {
     if (!SymbolizerProcess::ReadFromSymbolizer(buffer, max_length))
       return false;
+    // If buffer is empty and null-terminated, then input is longer than
+    // max_length, so simply skip this frame by returning.
+    if (*buffer == '\0')
+      return true;
     // We should cut out output_terminator_ at the end of given buffer,
     // appended by addr2line to mark the end of its meaningful output.
     // We cannot scan buffer from it's beginning, because it is legal for it
Index: lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc
===================================================================
--- lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc
+++ lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc
@@ -454,7 +454,7 @@
     if (ReachedEndOfOutput(buffer, read_len))
       break;
     if (read_len + 1 == max_length) {
-      Report("WARNING: Symbolizer buffer too small");
+      Report("WARNING: Symbolizer buffer too small\n");
       read_len = 0;
       break;
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36207.109269.patch
Type: text/x-patch
Size: 1359 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170802/89834077/attachment.bin>


More information about the llvm-commits mailing list