From patchwork Mon Feb 17 18:55:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 24789 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f200.google.com (mail-ie0-f200.google.com [209.85.223.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9F97F20468 for ; Mon, 17 Feb 2014 18:55:39 +0000 (UTC) Received: by mail-ie0-f200.google.com with SMTP id to1sf8852935ieb.11 for ; Mon, 17 Feb 2014 10:55:38 -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:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=QQE+RcSU+bJAfM7uVaSezUCEfLH0NKMpUUTE0jEJpkk=; b=BPBq+4z2hp5pRNtjtRY90TEDoj8/IsheGpW0AJvNIqNHAfD6SxXYVmTA+DGJP+K6KX 7LWyabdqPHu1/yETsDoRuOSVyYJnKSCxrpd9HdDzkQVA2JU3avpQ4G77c0rwdt32Bpz0 kxMnSMdpVJnUSZvJIlEoOVWFfC/dUmu/6HDVh/dZ/0YpbIokvC1ottpYjphbOC04g5FL L0x38HqiZ6k5U2CyUQVnOfX1Qm3J1qhMBqlCrtoaCrULR/hNc/VBFcgDE/wiBXZo+2Bi sESeBqUJOI6f+Vae1uWlB61+nubJF8qJM7R1lDyZ3XGHtmIXVoiSwx88TxIFgU8uhPTl UPWQ== X-Gm-Message-State: ALoCoQmJtkw+kAyuxjPHdrNB688NV1JN3NpK3rYPaI9VCdiGpcemkP3Mnm8iaVMGz52SMYo6HcRY X-Received: by 10.182.158.4 with SMTP id wq4mr11025208obb.18.1392663338873; Mon, 17 Feb 2014 10:55:38 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.100.146 with SMTP id s18ls951731qge.8.gmail; Mon, 17 Feb 2014 10:55:38 -0800 (PST) X-Received: by 10.52.181.199 with SMTP id dy7mr1946012vdc.43.1392663338783; Mon, 17 Feb 2014 10:55:38 -0800 (PST) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id a8si4680933vej.93.2014.02.17.10.55.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 17 Feb 2014 10:55:38 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.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.220.178; Received: by mail-vc0-f178.google.com with SMTP id ik5so12059273vcb.37 for ; Mon, 17 Feb 2014 10:55:38 -0800 (PST) X-Received: by 10.220.114.135 with SMTP id e7mr2292073vcq.39.1392663338688; Mon, 17 Feb 2014 10:55:38 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp160327vcz; Mon, 17 Feb 2014 10:55:38 -0800 (PST) X-Received: by 10.194.170.133 with SMTP id am5mr14773920wjc.42.1392663336829; Mon, 17 Feb 2014 10:55:36 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id fq9si9389788wib.64.2014.02.17.10.55.36 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 17 Feb 2014 10:55:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1WFTLr-0002EV-00; Mon, 17 Feb 2014 18:55:35 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Riku Voipio Subject: [PATCH 1/4] linux-user/elfload.c: Avoid calling g_free() on uninitialized data Date: Mon, 17 Feb 2014 18:55:31 +0000 Message-Id: <1392663334-8555-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1392663334-8555-1-git-send-email-peter.maydell@linaro.org> References: <1392663334-8555-1-git-send-email-peter.maydell@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.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 Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 --- 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)