From patchwork Thu Jul 29 16:37:01 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 60283 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id F41291007E2 for ; Fri, 30 Jul 2010 02:39:10 +1000 (EST) Received: from localhost ([127.0.0.1]:47676 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OeW8R-0005l3-8A for incoming@patchwork.ozlabs.org; Thu, 29 Jul 2010 12:39:07 -0400 Received: from [140.186.70.92] (port=38647 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OeW6e-0005G1-Rk for qemu-devel@nongnu.org; Thu, 29 Jul 2010 12:37:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OeW6d-0003Ee-FM for qemu-devel@nongnu.org; Thu, 29 Jul 2010 12:37:16 -0400 Received: from b.mail.sonic.net ([64.142.19.5]:48204) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OeW6d-0003EX-8E for qemu-devel@nongnu.org; Thu, 29 Jul 2010 12:37:15 -0400 Received: from are.twiddle.net (are.twiddle.net [75.101.38.216]) by b.mail.sonic.net (8.13.8.Beta0-Sonic/8.13.7) with ESMTP id o6TGb4Z8027270 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 29 Jul 2010 09:37:04 -0700 Received: from are.twiddle.net (localhost [127.0.0.1]) by are.twiddle.net (8.14.4/8.14.4) with ESMTP id o6TGb4uj022919; Thu, 29 Jul 2010 09:37:04 -0700 Received: (from rth@localhost) by are.twiddle.net (8.14.4/8.14.4/Submit) id o6TGb3Gl022917; Thu, 29 Jul 2010 09:37:03 -0700 From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 29 Jul 2010 09:37:01 -0700 Message-Id: <1280421421-22883-1-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.7.2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 Cc: edgar.iglesias@gmail.com Subject: [Qemu-devel] [PATCH] linux-user: Protect against allocation failure in load_symbols. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Cc: malc Signed-off-by: Richard Henderson --- linux-user/elfload.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index a53285a..33d776d 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1546,7 +1546,17 @@ static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias) } } + /* Attempt to free the storage associated with the local symbols + that we threw away. Whether or not this has any effect on the + memory allocation depends on the malloc implementation and how + many symbols we managed to discard. */ syms = realloc(syms, nsyms * sizeof(*syms)); + if (syms == NULL) { + free(s); + free(strings); + return; + } + qsort(syms, nsyms, sizeof(*syms), symcmp); s->disas_num_syms = nsyms;