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: 627163 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 3rGRqk1wDzz9sf9 for ; Fri, 27 May 2016 23:36:18 +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=R17j+Ctv; dkim-atps=neutral Received: from localhost ([::1]:45864 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6Hw0-0000H2-17 for incoming@patchwork.ozlabs.org; Fri, 27 May 2016 09:36:16 -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+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) {