From patchwork Wed May 25 10:32:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 68572 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp1141280qge; Wed, 25 May 2016 04:00:25 -0700 (PDT) X-Received: by 10.140.220.209 with SMTP id q200mr2940775qhb.18.1464174025579; Wed, 25 May 2016 04:00:25 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id a1si7284927qka.88.2016.05.25.04.00.25 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 25 May 2016 04:00:25 -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]:58928 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5WY5-0000ty-4j for patch@linaro.org; Wed, 25 May 2016 07:00:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41881) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5W7O-0001SX-Mw for qemu-devel@nongnu.org; Wed, 25 May 2016 06:33:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b5W7G-0003PM-8z for qemu-devel@nongnu.org; Wed, 25 May 2016 06:32:49 -0400 Received: from mail-lf0-x234.google.com ([2a00:1450:4010:c07::234]:35149) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5W7F-0003PC-SB for qemu-devel@nongnu.org; Wed, 25 May 2016 06:32:42 -0400 Received: by mail-lf0-x234.google.com with SMTP id w16so4194404lfd.2 for ; Wed, 25 May 2016 03:32:41 -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=DhI9QpOUYt9p0L8p6MNMFP4l4Ra0Bfuuqp7VKrLhcmRoUYkLZgCsdOch+FABL+VsHv RjdNuJoBsIZGq056hbuUYEQDwnvn3ki4yYucedVN7EGX4A2iPVzN6uRcKbF7USm42+tl 0wxfmdaGHruLbvB4vDJhBiXhK2K7JEGzySzl8= 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=Q1x0QREGSAFB5CSCgiO8jI2UgNjI8ro6GxENhloAbRx2KjSKXA0yjvuIKGxYvu0UKZ 8bCm4vxht5pAHo+afijEhT6opnLrmXb7J64r2Z879Eb4jTCemnp9FVW7OjHn4mm5h+Qe pqLL1vehx+yk1Zuxa4DLNawLQEdeTUEUyFJ9a9t8/qvaG+aeQ2mJNbKasJaRQL2gf6CS 2RE31FCntbAtHcVwyudEbWwFj8TGn580h/WXHun4MzrsYwHD/LzYaZo//AoKBxqu0qGq 6PWlIRcc7u1Et0N/gj51VABrUxi+4iDAwrh6NbGhO4y+UzO1Z3AcTuk3/s31rzQ3mxnM sj3Q== X-Gm-Message-State: ALyK8tL0WIT8b2wdPZS16zBvGsIrIvUg78jH+BWGFCY0cKoDgxC1OqI1o0mw5n4/YRpJEB3X X-Received: by 10.25.153.85 with SMTP id b82mr608692lfe.211.1464172361112; Wed, 25 May 2016 03:32:41 -0700 (PDT) Received: from beaming.home (91-157-168-132.elisa-laajakaista.fi. [91.157.168.132]) by smtp.gmail.com with ESMTPSA id o75sm1379610lfi.9.2016.05.25.03.32.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 May 2016 03:32:40 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Wed, 25 May 2016 13:32:03 +0300 Message-Id: <850f4d8a172c6f41cda02275834028906bfb419c.1464153942.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::234 Subject: [Qemu-devel] [PULL 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) {