From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 305 invoked by alias); 6 Jul 2011 14:40:50 -0000 Received: (qmail 32579 invoked by uid 22791); 6 Jul 2011 14:40:49 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,TVD_RCVD_SPACE_BRACKET,TW_BJ,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp.nokia.com (HELO mgw-sa02.nokia.com) (147.243.1.48) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 06 Jul 2011 14:40:34 +0000 Received: from nokia.com (localhost [127.0.0.1]) by mgw-sa02.nokia.com (Switch-3.4.4/Switch-3.4.3) with ESMTP id p66EdmI2005168; Wed, 6 Jul 2011 17:40:18 +0300 Received: from bettdhcp167109.europe.nokia.com ([bettdhcp167109.europe.nokia.com [172.25.167.109]]) by mgw-sa02.nokia.com with RELAY id p66EeEKp005906 ; Wed, 6 Jul 2011 17:40:15 +0300 Subject: Re: [PATCH,gdb,Update3]: ensures that cie ptr of an fda is a cie Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Fawzi Mohamed In-Reply-To: Date: Wed, 06 Jul 2011 14:45:00 -0000 Cc: ext Tristan Gingold , =?iso-8859-1?Q?Andr=E9_P=F6nitz?= Content-Transfer-Encoding: quoted-printable Message-Id: <0FC98010-6811-4715-BD3B-AE8B9221C7BF@nokia.com> References: To: gdb-patches@sourceware.org X-Nokia-AV: Clean Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-07/txt/msg00189.txt.bz2 On Jul 5, 2011, at 6:25 PM, ext Tom Tromey wrote: >>>>>> "Fawzi" =3D=3D Fawzi Mohamed writes: > [...] > I think enum constant names should be all caps. > That is the usual style. Ok thanks. > Fawzi> + gdb_assert ((entry_type & eh_cie_type_id)!=3D0); >=20 > It seems to me that this code is attempting to validate user input. If > so, an assertion is incorrect -- instead it should call either error or > warning and in the latter case also arrange for the bad data to be > ignored. What I do is to detect corrupt eh_sections. I have to say that I didn't see= eh_section as user input, but for a debugger it makes sense. I have used an error, because (at least in my case) this was triggered by a= nother gdb bug, so I guess that it is seldom enough that recovery is not re= quired (for recovery I guess one should nuke cie_table and fde_table, and t= hen artificially advance or try to reach the error handler, but I am not 10= 0% sure). The error message has a dot at the end there doesn't seem to be a consensus= on that, but I hope it is ok. So here is the updated patch: 2011-07-04 Fawzi Mohamed * dwarf2-frame.c (decode_frame_entry, decode_frame_entry_1): Ensure that CIE pointer of an FDE really points to a CIE . Index: gdb/dwarf2-frame.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/dwarf2-frame.c,v retrieving revision 1.125 diff -f -d -u -r1.125 dwarf2-frame.c --- gdb/dwarf2-frame.c 4 Jul 2011 16:30:09 -0000 1.125 +++ gdb/dwarf2-frame.c 6 Jul 2011 10:04:52 -0000 @@ -1801,17 +1801,30 @@ #define DW64_CIE_ID ~0 #endif +/* Defines the type of eh_frames that are expected to be decoded: CIE, FDE + or any of them. */ + +enum eh_frame_type +{ + EH_CIE_TYPE_ID =3D 1 << 0, + EH_FDE_TYPE_ID =3D 1 << 1, + EH_CIE_OR_FDE_TYPE_ID =3D EH_CIE_TYPE_ID + EH_FDE_TYPE_ID +}; + static gdb_byte *decode_frame_entry (struct comp_unit *unit, gdb_byte *star= t, int eh_frame_p, struct dwarf2_cie_table *cie_table, - struct dwarf2_fde_table *fde_table); + struct dwarf2_fde_table *fde_table, + enum eh_frame_type entry_type); + +/* Decode the next CIE or FDE, entry_type specifies the expected type. + Return NULL if invalid input, otherwise the next byte to be processed. = */ -/* Decode the next CIE or FDE. Return NULL if invalid input, otherwise - the next byte to be processed. */ static gdb_byte * decode_frame_entry_1 (struct comp_unit *unit, gdb_byte *start, int eh_frame= _p, struct dwarf2_cie_table *cie_table, - struct dwarf2_fde_table *fde_table) + struct dwarf2_fde_table *fde_table, + enum eh_frame_type entry_type) { struct gdbarch *gdbarch =3D get_objfile_arch (unit->objfile); gdb_byte *buf, *end; @@ -1862,6 +1875,10 @@ char *augmentation; unsigned int cie_version; + /* Check that a CIE was expected. */ + if ((entry_type & EH_CIE_TYPE_ID) =3D=3D 0) + error (_("Found a CIE when not expecting it, broken eh_info")); + /* Record the offset into the .debug_frame section of this CIE. */ cie_pointer =3D start - unit->dwarf_frame_buffer; @@ -2027,6 +2044,10 @@ /* This is a FDE. */ struct dwarf2_fde *fde; + /* Check that an FDE was expected. */ + if ((entry_type & EH_FDE_TYPE_ID) =3D=3D 0) + error (_("Found an FDE when not expecting it, broken eh_info.")); + /* In an .eh_frame section, the CIE pointer is the delta between the address within the FDE where the CIE pointer is stored and the address of the CIE. Convert it to an offset into the .eh_frame @@ -2048,7 +2069,8 @@ if (fde->cie =3D=3D NULL) { decode_frame_entry (unit, unit->dwarf_frame_buffer + cie_pointer, - eh_frame_p, cie_table, fde_table); + eh_frame_p, cie_table, fde_table, + EH_CIE_TYPE_ID); fde->cie =3D find_cie (cie_table, cie_pointer); } @@ -2089,11 +2111,14 @@ return end; } -/* Read a CIE or FDE in BUF and decode it. */ +/* Read a CIE or FDE in BUF and decode it. Entry_type specifies if we expe= ct + an FDE or a CIE. */ + static gdb_byte * decode_frame_entry (struct comp_unit *unit, gdb_byte *start, int eh_frame_p, struct dwarf2_cie_table *cie_table, - struct dwarf2_fde_table *fde_table) + struct dwarf2_fde_table *fde_table, + enum eh_frame_type entry_type) { enum { NONE, ALIGN4, ALIGN8, FAIL } workaround =3D NONE; gdb_byte *ret; @@ -2102,7 +2127,7 @@ while (1) { ret =3D decode_frame_entry_1 (unit, start, eh_frame_p, - cie_table, fde_table); + cie_table, fde_table,entry_type); if (ret !=3D NULL) break; @@ -2256,7 +2281,8 @@ frame_ptr =3D unit->dwarf_frame_buffer; while (frame_ptr < unit->dwarf_frame_buffer + unit->dwarf_frame_s= ize) frame_ptr =3D decode_frame_entry (unit, frame_ptr, 1, - &cie_table, &fde_table); + &cie_table, &fde_table, + EH_CIE_OR_FDE_TYPE_ID); if (cie_table.num_entries !=3D 0) { @@ -2277,7 +2303,8 @@ frame_ptr =3D unit->dwarf_frame_buffer; while (frame_ptr < unit->dwarf_frame_buffer + unit->dwarf_frame_size) frame_ptr =3D decode_frame_entry (unit, frame_ptr, 0, - &cie_table, &fde_table); + &cie_table, &fde_table, + EH_CIE_OR_FDE_TYPE_ID); } /* Discard the cie_table, it is no longer needed. */