From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 51557 invoked by alias); 16 Oct 2019 13:21:58 -0000 Mailing-List: contact elfutils-devel-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Post: List-Help: List-Subscribe: Sender: elfutils-devel-owner@sourceware.org Received: (qmail 51539 invoked by uid 48); 16 Oct 2019 13:21:54 -0000 From: "mark at klomp dot org" To: elfutils-devel@sourceware.org Subject: [Bug libasm/25068] Several crashes inside libasm Date: Wed, 16 Oct 2019 13:21:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: elfutils X-Bugzilla-Component: libasm X-Bugzilla-Version: unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: mark at klomp dot org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_status cf_reconfirmed_on cc everconfirmed Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2019-q4/txt/msg00018.txt.bz2 https://sourceware.org/bugzilla/show_bug.cgi?id=3D25068 Mark Wielaard changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |ASSIGNED Last reconfirmed| |2019-10-16 CC| |mark at klomp dot org Ever confirmed|0 |1 --- Comment #1 from Mark Wielaard --- Thanks for the example crashes. These seem caused by 2 asserts, a missing bounds check and an off-by-one bounds check. Which should be resolved by the following patch: diff --git a/libcpu/i386_data.h b/libcpu/i386_data.h index b8a34c3e..06356b8a 100644 --- a/libcpu/i386_data.h +++ b/libcpu/i386_data.h @@ -1336,7 +1336,7 @@ FCT_sel (struct output_data *d) { assert (d->opoff1 % 8 =3D=3D 0); assert (d->opoff1 / 8 =3D=3D 5); - if (*d->param_start + 2 > d->end) + if (*d->param_start + 2 >=3D d->end) return -1; *d->param_start +=3D 2; uint16_t absval =3D read_2ubyte_unaligned (&d->data[5]); diff --git a/libcpu/i386_disasm.c b/libcpu/i386_disasm.c index 8a206398..4422ffa2 100644 --- a/libcpu/i386_disasm.c +++ b/libcpu/i386_disasm.c @@ -610,7 +610,9 @@ i386_disasm (Ebl *ebl __attribute__((unused)), /* Account for displacement. */ if ((modrm & 0xc7) =3D=3D 5 || (modrm & 0xc0) =3D=3D 0x80 - || ((modrm & 0xc7) =3D=3D 0x4 && (codep[0] & 0x7) =3D= =3D 0x5)) + || ((modrm & 0xc7) =3D=3D 0x4 + && param_start < end + && (codep[0] & 0x7) =3D=3D 0x5)) param_start +=3D 4; else if ((modrm & 0xc0) =3D=3D 0x40) param_start +=3D 1; @@ -821,7 +823,8 @@ i386_disasm (Ebl *ebl __attribute__((unused)), } FALLTHROUGH; default: - assert (! "INVALID not handled"); + str =3D "INVALID not handled"; + break; } } else @@ -1124,8 +1127,9 @@ i386_disasm (Ebl *ebl __attribute__((unused)), /* Invalid (or at least unhandled) opcode. */ if (prefixes !=3D 0) goto print_prefix; - assert (*startp =3D=3D data); - ++data; + /* Make sure we get past the unrecognized opcode if we haven't yet. = */ + if (*startp =3D=3D data) + ++data; ADD_STRING ("(bad)"); addr +=3D data - begin; --=20 You are receiving this mail because: You are on the CC list for the bug.