From patchwork Wed Feb 19 10:35:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 24943 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yk0-f200.google.com (mail-yk0-f200.google.com [209.85.160.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 646CF201EE for ; Wed, 19 Feb 2014 10:38:28 +0000 (UTC) Received: by mail-yk0-f200.google.com with SMTP id q200sf753401ykb.3 for ; Wed, 19 Feb 2014 02:38:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=Ym/07avl/oCQDWNufL4jRHkkLkd1czctl5Y2eY9z6WA=; b=cGNsrt96VEkHuitrt+7ZyOZIW4NtFjlJtwK9QyHRcPlf6HnFWXZQ3ypq395jBnwQKI Dna0xXg4c8VLuiJf/oc59vtNLCmRHTA6ng8MP0VnGQn/RUeuxdXtg1QrH2u5wcpPyl2i 2TKa9bEKgqoFWl8ZX14tCM6viTDj29xLhFoS7E1qd+BxADX+xGNeArnw/CvmteOd1L+b E3AxHjFT8hhettInbYNvLL1T1Xtv6gitRitKJZjgwnvxhzhHKaEUjXRkzHvlrm8/5P+b dhHW0hTqz/az0Mtq4uhQuo8fqaW50VXG+LQscRL32SOeWjfQwj99vp1QZOdYkxJ3kxw3 AJWQ== X-Gm-Message-State: ALoCoQmowDHwTE3LnkWAKtNMpslbMltPqAW46BEaN0ZH213WoE6IjK0ok/3y+mLC/am8UVCs0GZ3 X-Received: by 10.236.111.73 with SMTP id v49mr12618869yhg.46.1392806308133; Wed, 19 Feb 2014 02:38:28 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.102.244 with SMTP id w107ls46696qge.26.gmail; Wed, 19 Feb 2014 02:38:28 -0800 (PST) X-Received: by 10.221.39.138 with SMTP id tm10mr25090048vcb.7.1392806307997; Wed, 19 Feb 2014 02:38:27 -0800 (PST) Received: from mail-ve0-f178.google.com (mail-ve0-f178.google.com [209.85.128.178]) by mx.google.com with ESMTPS id si7si6585333vdc.76.2014.02.19.02.38.27 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 19 Feb 2014 02:38:27 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.178; Received: by mail-ve0-f178.google.com with SMTP id oy12so181643veb.9 for ; Wed, 19 Feb 2014 02:38:27 -0800 (PST) X-Received: by 10.52.106.166 with SMTP id gv6mr28061vdb.86.1392806307880; Wed, 19 Feb 2014 02:38:27 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.174.196 with SMTP id u4csp287052vcz; Wed, 19 Feb 2014 02:38:27 -0800 (PST) X-Received: by 10.236.123.38 with SMTP id u26mr713443yhh.93.1392806307509; Wed, 19 Feb 2014 02:38:27 -0800 (PST) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id r18si29288352yhi.50.2014.02.19.02.38.27 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 19 Feb 2014 02:38:27 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:58105 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WG4Xr-0002WC-22 for patch@linaro.org; Wed, 19 Feb 2014 05:38:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49422) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WG4V8-00076p-Vw for qemu-devel@nongnu.org; Wed, 19 Feb 2014 05:35:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WG4V2-0007Ce-T1 for qemu-devel@nongnu.org; Wed, 19 Feb 2014 05:35:38 -0500 Received: from afflict.kos.to ([92.243.29.197]:33833) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WG4V2-0007Aq-8t for qemu-devel@nongnu.org; Wed, 19 Feb 2014 05:35:32 -0500 Received: from localhost.localdomain (afflict [92.243.29.197]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by afflict.kos.to (Postfix) with ESMTPSA id 7F8A326560; Wed, 19 Feb 2014 11:35:30 +0100 (CET) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Wed, 19 Feb 2014 12:35:25 +0200 Message-Id: <6afafa86f3446f5e6dd410cc2c442e98adabc26c.1392805802.git.riku.voipio@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 92.243.29.197 Cc: Peter Maydell Subject: [Qemu-devel] [PATCH 2/6] linux-user/elfload.c: Avoid calling g_free() on uninitialized data X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: riku.voipio@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Peter Maydell Avoid calling g_free() on unintialized data in the error-handling paths in elf_core_dump() by splitting the initialization of the elf_note_info struct out of fill_note_info() so that it's always valid to call free_note_info() whether we got to the point of being able to fill_note_info() or not. Signed-off-by: Peter Maydell Signed-off-by: Riku Voipio --- linux-user/elfload.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 5902f16..c0687e3 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2636,6 +2636,16 @@ static void fill_thread_info(struct elf_note_info *info, const CPUArchState *env info->notes_size += note_size(&ets->notes[0]); } +static void init_note_info(struct elf_note_info *info) +{ + /* Initialize the elf_note_info structure so that it is at + * least safe to call free_note_info() on it. Must be + * called before calling fill_note_info(). + */ + memset(info, 0, sizeof (*info)); + QTAILQ_INIT(&info->thread_list); +} + static int fill_note_info(struct elf_note_info *info, long signr, const CPUArchState *env) { @@ -2644,10 +2654,6 @@ static int fill_note_info(struct elf_note_info *info, TaskState *ts = (TaskState *)env->opaque; int i; - (void) memset(info, 0, sizeof (*info)); - - QTAILQ_INIT(&info->thread_list); - info->notes = g_malloc0(NUMNOTES * sizeof (struct memelfnote)); if (info->notes == NULL) return (-ENOMEM); @@ -2781,6 +2787,8 @@ static int elf_core_dump(int signr, const CPUArchState *env) int segs = 0; int fd = -1; + init_note_info(&info); + errno = 0; getrlimit(RLIMIT_CORE, &dumpsize); if (dumpsize.rlim_cur == 0)