From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id A40AB384AB66; Thu, 18 Apr 2024 01:02:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A40AB384AB66 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1713402157; bh=FdVjxLhKdWgaL5cYi/sdzuysU5+3fE0fP4h+ScnIcxA=; h=From:To:Subject:Date:From; b=oka4DvEQYCFMbE9w63QJApdf21eDKYK848Ms+m2+y+3KHM/LpxoqLYTZAIzTvslLX k4hPgIbHrKAEByoEW4MXC3z1/PngbkuiOOCXkbFcpJiD5xzHIgWKtJj3bnoLRtKeDS 9uMvSu4B6fV80FjfxLojlXMmVO7AYVXXocuENjUM= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Alan Modra To: binutils-cvs@sourceware.org Subject: [binutils-gdb] Re: Fix address violations when reading corrupt VMS records X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/master X-Git-Oldrev: ee19a4725c01f4924657a1d6f09f0e4dcd6bba17 X-Git-Newrev: ebf18671351d94185823d364b75369abc1baba31 Message-Id: <20240418010237.A40AB384AB66@sourceware.org> Date: Thu, 18 Apr 2024 01:02:37 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Debf18671351d= 94185823d364b75369abc1baba31 commit ebf18671351d94185823d364b75369abc1baba31 Author: Alan Modra Date: Wed Apr 17 22:28:23 2024 +0930 Re: Fix address violations when reading corrupt VMS records =20 Fixes error reports about the length of EEOM records produced by gas. =20 PR 21618 * vms-alpha.c (evax_bfd_print_emh): Don't read subtyp if short record. Consolidate error messages. (evax_bfd_print_eeom): Allow length 10 record. Diff: --- bfd/vms-alpha.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/bfd/vms-alpha.c b/bfd/vms-alpha.c index 8b5e3c21ac6..404638cf3d9 100644 --- a/bfd/vms-alpha.c +++ b/bfd/vms-alpha.c @@ -6110,20 +6110,23 @@ static void evax_bfd_print_emh (FILE *file, unsigned char *rec, unsigned int rec_len) { struct vms_emh_common *emh =3D (struct vms_emh_common *)rec; - unsigned int subtype; + int subtype =3D -1; int extra; =20 - subtype =3D (unsigned) bfd_getl16 (emh->subtyp); + if (rec_len >=3D sizeof (*emh)) + subtype =3D bfd_getl16 (emh->subtyp); =20 /* xgettext:c-format */ - fprintf (file, _(" EMH %u (len=3D%u): "), subtype, rec_len); + fprintf (file, _(" EMH %d (len=3D%u): "), subtype, rec_len); =20 /* PR 21618: Check for invalid lengths. */ - if (rec_len < sizeof (* emh)) + if (rec_len < sizeof (*emh)) { - fprintf (file, _(" Error: The length is less than the length of an= EMH record\n")); + fprintf (file, _(" Error: %s min length is %u\n"), + "EMH", (unsigned) sizeof (*emh)); return; } + extra =3D rec_len - sizeof (struct vms_emh_common); =20 switch (subtype) @@ -6138,7 +6141,8 @@ evax_bfd_print_emh (FILE *file, unsigned char *rec, u= nsigned int rec_len) /* PR 21840: Check for invalid lengths. */ if (rec_len < sizeof (* mhd)) { - fprintf (file, _(" Error: The record length is less than the size o= f an EMH_MHD record\n")); + fprintf (file, _(" Error: %s min length is %u\n"), + "EMH_MHD", (unsigned) sizeof (*mhd)); return; } fprintf (file, _("Module header\n")); @@ -6214,9 +6218,10 @@ evax_bfd_print_eeom (FILE *file, unsigned char *rec,= unsigned int rec_len) fprintf (file, _(" EEOM (len=3D%u):\n"), rec_len); =20 /* PR 21618: Check for invalid lengths. */ - if (rec_len < sizeof (* eeom)) + if (rec_len < 10) { - fprintf (file, _(" Error: The length is less than the length of an= EEOM record\n")); + fprintf (file, _(" Error: %s min length is %u\n"), + "EEOM", 10); return; } =20 @@ -6224,7 +6229,8 @@ evax_bfd_print_eeom (FILE *file, unsigned char *rec, = unsigned int rec_len) (unsigned)bfd_getl32 (eeom->total_lps)); fprintf (file, _(" completion code: %u\n"), (unsigned)bfd_getl16 (eeom->comcod)); - if (rec_len > 10) + + if (rec_len >=3D sizeof (*eeom)) { fprintf (file, _(" transfer addr flags: 0x%02x\n"), eeom->tfrflg); fprintf (file, _(" transfer addr psect: %u\n"),