From patchwork Wed Feb 19 10:35:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 24939 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f198.google.com (mail-pd0-f198.google.com [209.85.192.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D51C4201EE for ; Wed, 19 Feb 2014 10:36:50 +0000 (UTC) Received: by mail-pd0-f198.google.com with SMTP id v10sf441402pde.5 for ; Wed, 19 Feb 2014 02:36:50 -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=F9/Vn45B22Lxq3FiHjeW0lHC6tHhx/9wbV5i3iK5LuI=; b=NsIw4ze4TX5iaiB+CJSsLmzjCJfWq9zNkWrCTmNv5cGX5Orl0sxjA8qcdPAcCV4FjS XFwdAl9SKlpZKxmHAfsgg3dgCAoLv9+nv0HLXkMoEPzIsX8vmYq4LLp8C3eRYA6Ixb5H Z9mMxh4FVm51FrOc4GpiCrRO5icr04DtIV96beZnit1IBs4VzCCKaMdti5gLivWLLU0E INaC6wuqFIAxkSWgoqxuu1oS7Kem2xCniz5sXt0xDFMsMjWKQGwkFrNdddn+J/2DneLw SfdfIsJJ6BURZTNnXnIaYRgZb1DF+9JqP8YggjrFMfGXmFlFgOIP/YaS8+mloN71T+8s 8Emg== X-Gm-Message-State: ALoCoQkxnzEooPE765wLhWYD68ocFOAFzvO9UE1qs9AfEuFTKkNoeR3/jQJK3vUWbZgpCXY0DxjW X-Received: by 10.66.140.8 with SMTP id rc8mr466087pab.41.1392806210103; Wed, 19 Feb 2014 02:36:50 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.33.200 with SMTP id j66ls34142qgj.80.gmail; Wed, 19 Feb 2014 02:36:49 -0800 (PST) X-Received: by 10.220.0.131 with SMTP id 3mr31046vcb.79.1392806209943; Wed, 19 Feb 2014 02:36:49 -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 y3si6578734vdo.110.2014.02.19.02.36.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 19 Feb 2014 02:36:49 -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 oy12so178002veb.37 for ; Wed, 19 Feb 2014 02:36:49 -0800 (PST) X-Received: by 10.52.107.35 with SMTP id gz3mr20813437vdb.8.1392806209877; Wed, 19 Feb 2014 02:36:49 -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 u4csp286932vcz; Wed, 19 Feb 2014 02:36:49 -0800 (PST) X-Received: by 10.236.230.3 with SMTP id i3mr41944350yhq.13.1392806209524; Wed, 19 Feb 2014 02:36:49 -0800 (PST) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id x58si29280912yhh.145.2014.02.19.02.36.49 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 19 Feb 2014 02:36:49 -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]:58086 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WG4WG-0008Gb-VL for patch@linaro.org; Wed, 19 Feb 2014 05:36:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49431) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WG4V9-00076t-CM for qemu-devel@nongnu.org; Wed, 19 Feb 2014 05:35:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WG4V3-0007D2-Bw for qemu-devel@nongnu.org; Wed, 19 Feb 2014 05:35:39 -0500 Received: from afflict.kos.to ([92.243.29.197]:33844) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WG4V3-0007CG-2l for qemu-devel@nongnu.org; Wed, 19 Feb 2014 05:35:33 -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 B664126564; 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:29 +0200 Message-Id: <69d4c703a549f0630793a67b16a8fc6bc14c8654.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 6/6] linux-user: Fix error handling in target_to_host_semarray() 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 Fix two issues in error handling in target_to_host_semarray(): * don't leak the host_array buffer if lock_user fails * return an error if malloc() fails v2: added missing * -Riku Voipio Signed-off-by: Peter Maydell Signed-off-by: Riku Voipio --- linux-user/syscall.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 8f5a58e..1407b7a 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -2430,10 +2430,15 @@ static inline abi_long target_to_host_semarray(int semid, unsigned short **host_ nsems = semid_ds.sem_nsems; *host_array = malloc(nsems*sizeof(unsigned short)); + if (!*host_array) { + return -TARGET_ENOMEM; + } array = lock_user(VERIFY_READ, target_addr, nsems*sizeof(unsigned short), 1); - if (!array) + if (!array) { + free(*host_array); return -TARGET_EFAULT; + } for(i=0; i