]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
readelf: Robustify print_cfa_program.
authorMark Wielaard <mjw@redhat.com>
Sun, 16 Nov 2014 10:40:08 +0000 (11:40 +0100)
committerMark Wielaard <mjw@redhat.com>
Sun, 16 Nov 2014 10:40:49 +0000 (11:40 +0100)
Check block len before calling print_ops.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
src/ChangeLog
src/readelf.c

index 756104173809a31cbe969b41550af60569c2c3ff..fefd6c1d95cb9c5578a068c7ae1298d13564b2b5 100644 (file)
@@ -1,3 +1,8 @@
+2014-11-16  Mark Wielaard  <mjw@redhat.com>
+
+       * readelf.c (print_cfa_program): Check block len before calling
+       print_ops.
+
 2014-11-14  Mark Wielaard  <mjw@redhat.com>
 
        * readelf.c (print_debug_frame_section): Sanity Check CIE
index 065ee1c34e8aa5c5fce3dad18e3a9cd221eb5e18..697a0e5071de2c8bbd013874c343f2fc3bdfe6d6 100644 (file)
@@ -4980,6 +4980,12 @@ print_cfa_program (const unsigned char *readp, const unsigned char *const endp,
            // XXX overflow check
            get_uleb128 (op1, readp);   /* Length of DW_FORM_block.  */
            printf ("     def_cfa_expression %" PRIu64 "\n", op1);
+           if ((uint64_t) (endp - readp) < op1)
+             {
+           invalid:
+               fputs (gettext ("         <INVALID DATA>\n"), stdout);
+               return;
+             }
            print_ops (dwflmod, dbg, 10, 10, version, ptr_size, 0, NULL,
                       op1, readp);
            readp += op1;
@@ -4990,6 +4996,8 @@ print_cfa_program (const unsigned char *readp, const unsigned char *const endp,
            get_uleb128 (op2, readp);   /* Length of DW_FORM_block.  */
            printf ("     expression r%" PRIu64 " (%s) \n",
                    op1, regname (op1));
+           if ((uint64_t) (endp - readp) < op1)
+             goto invalid;
            print_ops (dwflmod, dbg, 10, 10, version, ptr_size, 0, NULL,
                       op2, readp);
            readp += op2;
@@ -5034,6 +5042,8 @@ print_cfa_program (const unsigned char *readp, const unsigned char *const endp,
            get_uleb128 (op2, readp);   /* Length of DW_FORM_block.  */
            printf ("     val_expression r%" PRIu64 " (%s)\n",
                    op1, regname (op1));
+           if ((uint64_t) (endp - readp) < op2)
+             goto invalid;
            print_ops (dwflmod, dbg, 10, 10, version, ptr_size, 0,
                       NULL, op2, readp);
            readp += op2;