From patchwork Mon Feb 17 18:55:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 24791 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f70.google.com (mail-yh0-f70.google.com [209.85.213.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E278B20468 for ; Mon, 17 Feb 2014 18:55:40 +0000 (UTC) Received: by mail-yh0-f70.google.com with SMTP id c41sf33869585yho.1 for ; Mon, 17 Feb 2014 10:55:40 -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=QWX3ENAxq0tQNJCkS+gu2HcfK2rY+aNVsnJ0IIoA6Vc=; b=RsxDGKLZXAVFL3H2RQDzkjBPUpq9Bx6m3ESXubT94m3u1vS8guvzkSRm3Q1YE31fJs XuBai8/2RwvmlVsXKOITkd8/w1wZphtvKFU4DMdFNSwtkqfwfRVkTH1ecNv3TPe66ZWX Ymnuy274KqmOCLBQSXvNPZiybETA3NH54Ts98MA3r8dAus4UBgQQ9xW81lm7VR/664AP S+rdB/3/16WdpsE98ZJNSwabedK972F1uffz+FOkC9ZBMLcoMwyLUDGp2WB64QQ+I85F 4Z/ZQ/NKjAuV/o/AcH42GlUffEXJxTd9NNF2+hoUv9CqvS04p97+AlaxsxtHO3P8VHWJ kGLA== X-Gm-Message-State: ALoCoQk15VrQzLlJzBbZLlxhO3uB+3Hfw2esv638uZxJHfyyFeYrUNTW6Xvt9vlML3+nliu3mX3z X-Received: by 10.236.96.138 with SMTP id r10mr8850991yhf.12.1392663340088; Mon, 17 Feb 2014 10:55:40 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.34.76 with SMTP id k70ls1078078qgk.30.gmail; Mon, 17 Feb 2014 10:55:40 -0800 (PST) X-Received: by 10.220.88.204 with SMTP id b12mr17873123vcm.3.1392663340003; Mon, 17 Feb 2014 10:55:40 -0800 (PST) Received: from mail-ve0-f182.google.com (mail-ve0-f182.google.com [209.85.128.182]) by mx.google.com with ESMTPS id ku3si201963veb.136.2014.02.17.10.55.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 17 Feb 2014 10:55:39 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.182 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.182; Received: by mail-ve0-f182.google.com with SMTP id jy13so12847396veb.27 for ; Mon, 17 Feb 2014 10:55:39 -0800 (PST) X-Received: by 10.52.168.39 with SMTP id zt7mr1925094vdb.42.1392663339942; Mon, 17 Feb 2014 10:55:39 -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 u4csp160332vcz; Mon, 17 Feb 2014 10:55:39 -0800 (PST) X-Received: by 10.112.132.131 with SMTP id ou3mr17620511lbb.29.1392663337408; Mon, 17 Feb 2014 10:55:37 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id no3si26768018lbb.110.2014.02.17.10.55.36 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 17 Feb 2014 10:55:37 -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-0002Eh-4K; Mon, 17 Feb 2014 18:55:35 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Riku Voipio Subject: [PATCH 4/4] linux-user: Fix error handling in target_to_host_semarray() Date: Mon, 17 Feb 2014 18:55:34 +0000 Message-Id: <1392663334-8555-5-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.128.182 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: , 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 Signed-off-by: Peter Maydell --- 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 bb3e4b1..c92f026 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -2429,10 +2429,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