From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5884 invoked by alias); 23 Jul 2012 12:41:47 -0000 Received: (qmail 5870 invoked by uid 22791); 23 Jul 2012 12:41:45 -0000 X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,MAY_BE_FORGED,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 23 Jul 2012 12:41:27 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q6NCfQnZ019054 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 23 Jul 2012 08:41:26 -0400 Received: from spoyarek (dhcp223-8.pnq.redhat.com [10.65.223.8] (may be forged)) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q6NCfO6b003529 for ; Mon, 23 Jul 2012 08:41:25 -0400 Date: Mon, 23 Jul 2012 12:41:00 -0000 From: Siddhesh Poyarekar To: gdb-patches@sourceware.org Subject: [PATCH] Remove more instances of unsafe alloca Message-ID: <20120723181116.00a4b508@spoyarek> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/MhbO3V/bIEHKuJKvLo/cKgi" 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: 2012-07/txt/msg00440.txt.bz2 --MP_/MhbO3V/bIEHKuJKvLo/cKgi Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline Content-length: 593 Hi, I found another couple of instances of unsafe alloca usage in gdb, both to do with trying to allocate memory on stack for a baseclass type. The fix is on the lines of what was done in the following changeset: http://sourceware.org/ml/gdb-cvs/2012-07/msg00044.html I have verified that the fix does not cause any regressions on x86_64. OK to commit? Regards, Siddhesh gdb/ChangeLog: 2012-07-23 Siddhesh Poyarekar * p-valprint.c (pascal_object_print_value): Replace potentially unsafe alloca with xmalloc/xfree. * valops.c (search_struct_method): Likewise. --MP_/MhbO3V/bIEHKuJKvLo/cKgi Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=alloca-cleanup.patch Content-length: 1929 ? alloca-cleanup.patch Index: gdb/p-valprint.c =================================================================== RCS file: /cvs/src/src/gdb/p-valprint.c,v retrieving revision 1.100 diff -u -r1.100 p-valprint.c --- gdb/p-valprint.c 18 May 2012 21:02:49 -0000 1.100 +++ gdb/p-valprint.c 23 Jul 2012 12:34:37 -0000 @@ -797,8 +797,11 @@ if (boffset < 0 || boffset >= TYPE_LENGTH (type)) { - /* FIXME (alloc): not safe is baseclass is really really big. */ - gdb_byte *buf = alloca (TYPE_LENGTH (baseclass)); + gdb_byte *buf; + struct cleanup *back_to; + + buf = xmalloc (TYPE_LENGTH (baseclass)); + back_to = make_cleanup (xfree, buf); base_valaddr = buf; if (target_read_memory (address + boffset, buf, @@ -807,6 +810,7 @@ address = address + boffset; thisoffset = 0; boffset = 0; + do_cleanups (back_to); } else base_valaddr = valaddr; Index: gdb/valops.c =================================================================== RCS file: /cvs/src/src/gdb/valops.c,v retrieving revision 1.297 diff -u -r1.297 valops.c --- gdb/valops.c 24 Jun 2012 07:28:10 -0000 1.297 +++ gdb/valops.c 23 Jul 2012 12:34:40 -0000 @@ -2281,8 +2281,13 @@ if (offset < 0 || offset >= TYPE_LENGTH (type)) { - gdb_byte *tmp = alloca (TYPE_LENGTH (baseclass)); - CORE_ADDR address = value_address (*arg1p); + gdb_byte *tmp; + struct cleanup *back_to; + CORE_ADDR address; + + tmp = xmalloc (TYPE_LENGTH (baseclass)); + back_to = make_cleanup (xfree, tmp); + address = value_address (*arg1p); if (target_read_memory (address + offset, tmp, TYPE_LENGTH (baseclass)) != 0) @@ -2293,6 +2298,7 @@ address + offset); base_valaddr = value_contents_for_printing (base_val); this_offset = 0; + do_cleanups (back_to); } else { --MP_/MhbO3V/bIEHKuJKvLo/cKgi--