]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
readelf: While printing .debug_loc make sure that next_off doesn't overflow.
authorMark Wielaard <mark@klomp.org>
Wed, 13 Jun 2018 13:21:37 +0000 (15:21 +0200)
committerMark Wielaard <mark@klomp.org>
Fri, 15 Jun 2018 22:20:53 +0000 (00:20 +0200)
Found by the afl fuzzer. The next offset (after a locview) comes from a
DIE loclist attribute. This could be a bogus value so large it overflows
the buffer and makes us print past the end of buffer.

Signed-off-by: Mark Wielaard <mark@klomp.org>
src/ChangeLog
src/readelf.c

index 5f381cf8f3dff0cf80989b342eb70aa66a79aeea..3d266e23db8c824ca4e8094db43a731fb62cabe9 100644 (file)
@@ -1,3 +1,8 @@
+2018-06-16  Mark Wielaard  <mark@klomp.org>
+
+       * readelf.c (print_debug_loc_section): Make sure next_off doesn't
+       overflow d_buf.
+
 2018-06-13  Mark Wielaard  <mark@klomp.org>
 
        * readelf.c (die_type_sign_bytes): New function.
index c9efd795a78930e39b9532ae3958ad0bbbecbcc2..720d7f3fea1285e8d57166bd0df9353cb841d407 100644 (file)
@@ -9310,7 +9310,9 @@ print_debug_loc_section (Dwfl_Module *dwflmod,
                                                    listptr_idx);
          const unsigned char *locp = readp;
          const unsigned char *locendp;
-         if (next_off == 0)
+         if (next_off == 0
+             || next_off > (size_t) (endp
+                                     - (const unsigned char *) data->d_buf))
            locendp = endp;
          else
            locendp = (const unsigned char *) data->d_buf + next_off;