From patchwork Fri May 27 13:00:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 68745 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp94115qge; Fri, 27 May 2016 06:37:13 -0700 (PDT) X-Received: by 10.140.91.53 with SMTP id y50mr12890636qgd.104.1464356233817; Fri, 27 May 2016 06:37:13 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id v139si17500469qhb.128.2016.05.27.06.37.13 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 27 May 2016 06:37:13 -0700 (PDT) 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; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:45864 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6Hwv-0000H2-8J for patch@linaro.org; Fri, 27 May 2016 09:37:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37549) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6HO9-0007rd-Q0 for qemu-devel@nongnu.org; Fri, 27 May 2016 09:01:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b6HO4-0001L0-Ho for qemu-devel@nongnu.org; Fri, 27 May 2016 09:01:16 -0400 Received: from mail-lf0-x22b.google.com ([2a00:1450:4010:c07::22b]:35354) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6HO4-0001Ki-Aa for qemu-devel@nongnu.org; Fri, 27 May 2016 09:01:12 -0400 Received: by mail-lf0-x22b.google.com with SMTP id w16so33412393lfd.2 for ; Fri, 27 May 2016 06:01:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BqCA4YBXjIW7rXvnZ7w9UI26auAMsMcJ+FZ3uSW70/w=; b=R17j+CtvWwLXy4KbEHp7SAyWKbjXs9rnSwORFwTEHRO1/SQ4/Et/oJwmlCbon2DlJo JSjbgFaJt/AETFEnxTBMdymveP+kfgFOsrqVGQItK/3pg53X50xOBhQ/FKMdGP+6eCOC 7V8COiYR5UKYkfdcyUgW9Ch9LSWBhW14sARHg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BqCA4YBXjIW7rXvnZ7w9UI26auAMsMcJ+FZ3uSW70/w=; b=eu2iGpvX10FWcacQoWE4HVyZYF1d1CSEY1tpB+6Q/pqormqi3APCwblmTWvJ+UpXTx e7YmCNRWjDRpZ4T0yO8Ty5HJQzSsvCZbTWqNinaeuDgLRg22b8vpftFRHHODq8iMk19W Hgu+a/SANdiUqEqXyMw7sm9DADuXmDWuWKdwFhslJG6eUce4nZqAtqmQdmSrvUw6VOiu bAtdUchVJylsEC2SGPhoEz2VVlIR7NFTVPBdHycT1PrfINgeVAyR94EfyAWg7DAJHiNu PO0+5M7Oj6stoDTlJ0Kd9jVBdhsuoD65R5iyoG8LimQ8hV/cwkAJESVPi6gn3fJk5k9m PQeQ== X-Gm-Message-State: ALyK8tJyk4/H3lmqJo0hXyp1Zfa1x888OVL+CZgRJLCY0qtGFVHeXlwk8zthWo3dcH9ZO74A X-Received: by 10.46.33.96 with SMTP id h93mr1653781ljh.45.1464354071456; Fri, 27 May 2016 06:01:11 -0700 (PDT) Received: from beaming.home (91-157-168-132.elisa-laajakaista.fi. [91.157.168.132]) by smtp.gmail.com with ESMTPSA id n16sm2281066lfg.31.2016.05.27.06.01.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 May 2016 06:01:10 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Fri, 27 May 2016 16:00:22 +0300 Message-Id: <415d847110e3f8cd176160b92a5fdc56d8a20792.1464353863.git.riku.voipio@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::22b Subject: [Qemu-devel] [PULL v2 31/38] linux-user: Use g_try_malloc() in do_msgrcv() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell In do_msgrcv() we want to allocate a message buffer, whose size is passed to us by the guest. That means we could legitimately fail, so use g_try_malloc() and handle the error case, in the same way that do_msgsnd() does. Signed-off-by: Peter Maydell Signed-off-by: Riku Voipio --- linux-user/syscall.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) -- 2.1.4 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index cec5b80..40e8742 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3167,7 +3167,11 @@ static inline abi_long do_msgrcv(int msqid, abi_long msgp, if (!lock_user_struct(VERIFY_WRITE, target_mb, msgp, 0)) return -TARGET_EFAULT; - host_mb = g_malloc(msgsz+sizeof(long)); + host_mb = g_try_malloc(msgsz + sizeof(long)); + if (!host_mb) { + ret = -TARGET_ENOMEM; + goto end; + } ret = get_errno(msgrcv(msqid, host_mb, msgsz, msgtyp, msgflg)); if (ret > 0) {