From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25279 invoked by alias); 17 Jul 2007 12:47:19 -0000 Received: (qmail 25269 invoked by uid 22791); 17 Jul 2007 12:47:18 -0000 X-Spam-Check-By: sourceware.org Received: from NaN.false.org (HELO nan.false.org) (208.75.86.248) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 17 Jul 2007 12:47:15 +0000 Received: from nan.false.org (localhost [127.0.0.1]) by nan.false.org (Postfix) with ESMTP id 72122982C3 for ; Tue, 17 Jul 2007 12:47:14 +0000 (GMT) Received: from caradoc.them.org (22.svnf5.xdsl.nauticom.net [209.195.183.55]) by nan.false.org (Postfix) with ESMTP id 4B539982A3 for ; Tue, 17 Jul 2007 12:47:14 +0000 (GMT) Received: from drow by caradoc.them.org with local (Exim 4.67) (envelope-from ) id 1IAmSO-0004hh-0W for gdb-patches@sourceware.org; Tue, 17 Jul 2007 08:47:12 -0400 Date: Tue, 17 Jul 2007 12:52:00 -0000 From: Daniel Jacobowitz To: gdb-patches@sourceware.org Subject: Re: [rfc] Detect dwarf address size mismatch Message-ID: <20070717124711.GA27936@caradoc.them.org> Mail-Followup-To: gdb-patches@sourceware.org References: <20070711141912.GA12298@caradoc.them.org> <20070711194141.GA28114@caradoc.them.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.15 (2007-04-09) X-IsSubscribed: yes 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: 2007-07/txt/msg00215.txt.bz2 On Wed, Jul 11, 2007 at 01:30:48PM -0700, Jim Blandy wrote: > True. But I think the check should go after the switch in any case; > there's no reason to only apply sanity checking to that one opcode. Reasonable enough. I've checked in this version. -- Daniel Jacobowitz CodeSourcery 2007-07-17 Daniel Jacobowitz * dwarf2read.c (dwarf_decode_lines): Detect address size mismatches. Index: dwarf2read.c =================================================================== RCS file: /cvs/src/src/gdb/dwarf2read.c,v retrieving revision 1.227 diff -u -p -r1.227 dwarf2read.c --- dwarf2read.c 22 Jun 2007 12:26:59 -0000 1.227 +++ dwarf2read.c 17 Jul 2007 12:45:22 -0000 @@ -6668,9 +6668,9 @@ static void dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd, struct dwarf2_cu *cu, struct partial_symtab *pst) { - gdb_byte *line_ptr; + gdb_byte *line_ptr, *extended_end; gdb_byte *line_end; - unsigned int bytes_read; + unsigned int bytes_read, extended_len; unsigned char op_code, extended_op, adj_opcode; CORE_ADDR baseaddr; struct objfile *objfile = cu->objfile; @@ -6745,8 +6745,9 @@ dwarf_decode_lines (struct line_header * else switch (op_code) { case DW_LNS_extended_op: - read_unsigned_leb128 (abfd, line_ptr, &bytes_read); + extended_len = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); line_ptr += bytes_read; + extended_end = line_ptr + extended_len; extended_op = read_1_byte (abfd, line_ptr); line_ptr += 1; switch (extended_op) @@ -6792,6 +6793,15 @@ dwarf_decode_lines (struct line_header * _("mangled .debug_line section")); return; } + /* Make sure that we parsed the extended op correctly. If e.g. + we expected a different address size than the producer used, + we may have read the wrong number of bytes. */ + if (line_ptr != extended_end) + { + complaint (&symfile_complaints, + _("mangled .debug_line section")); + return; + } break; case DW_LNS_copy: if (lh->num_file_names < file)