[PATCH] D77304: [llvm/Support] Don't crash on empty nullptr ranges when decoding LEBs

Pavel Labath via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 6 05:23:06 PDT 2020


This revision was automatically updated to reflect the committed changes.
labath marked an inline comment as done.
Closed by commit rG8f1233699bf6: [llvm/Support] Don't crash on empty nullptr ranges when decoding LEBs (authored by labath).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77304/new/

https://reviews.llvm.org/D77304

Files:
  llvm/include/llvm/Support/LEB128.h
  llvm/unittests/Support/LEB128Test.cpp


Index: llvm/unittests/Support/LEB128Test.cpp
===================================================================
--- llvm/unittests/Support/LEB128Test.cpp
+++ llvm/unittests/Support/LEB128Test.cpp
@@ -113,6 +113,9 @@
     EXPECT_EQ(EXPECTED, Actual); \
   } while (0)
 
+  // Don't crash
+  EXPECT_EQ(0u, decodeULEB128(nullptr, nullptr, nullptr));
+
   // Decode ULEB128
   EXPECT_DECODE_ULEB128_EQ(0u, "\x00");
   EXPECT_DECODE_ULEB128_EQ(1u, "\x01");
@@ -148,6 +151,9 @@
     EXPECT_EQ(EXPECTED, Actual); \
   } while (0)
 
+  // Don't crash
+  EXPECT_EQ(0, decodeSLEB128(nullptr, nullptr, nullptr));
+
   // Decode SLEB128
   EXPECT_DECODE_SLEB128_EQ(0L, "\x00");
   EXPECT_DECODE_SLEB128_EQ(1L, "\x01");
Index: llvm/include/llvm/Support/LEB128.h
===================================================================
--- llvm/include/llvm/Support/LEB128.h
+++ llvm/include/llvm/Support/LEB128.h
@@ -134,7 +134,7 @@
   if (error)
     *error = nullptr;
   do {
-    if (end && p == end) {
+    if (p == end) {
       if (error)
         *error = "malformed uleb128, extends past end";
       if (n)
@@ -168,7 +168,7 @@
   if (error)
     *error = nullptr;
   do {
-    if (end && p == end) {
+    if (p == end) {
       if (error)
         *error = "malformed sleb128, extends past end";
       if (n)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77304.255296.patch
Type: text/x-patch
Size: 1302 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200406/d4d2d37a/attachment.bin>


More information about the llvm-commits mailing list