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: 626118 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rF8Rn51WVz9ssM for ; Wed, 25 May 2016 20:59:33 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b=DhI9QpOU; dkim-atps=neutral Received: from localhost ([::1]:58928 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5WXC-0000ty-Ir for incoming@patchwork.ozlabs.org; Wed, 25 May 2016 06:59:30 -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+incoming=patchwork.ozlabs.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(-) 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) {