From patchwork Wed May 25 05:27:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 9134735 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A592A607D3 for ; Wed, 25 May 2016 05:33:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B6E528166 for ; Wed, 25 May 2016 05:33:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 90876282AF; Wed, 25 May 2016 05:33:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, FSL_HELO_HOME, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7A3A728166 for ; Wed, 25 May 2016 05:33:23 +0000 (UTC) Received: from localhost ([::1]:57393 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5RRa-0003Bk-Ip for patchwork-qemu-devel@patchwork.kernel.org; Wed, 25 May 2016 01:33:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33725) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5RMs-0007zz-9Y for qemu-devel@nongnu.org; Wed, 25 May 2016 01:28:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b5RMn-0001Kq-1w for qemu-devel@nongnu.org; Wed, 25 May 2016 01:28:29 -0400 Received: from mail-lb0-x22e.google.com ([2a00:1450:4010:c04::22e]:36125) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5RMm-0001Jz-Ge for qemu-devel@nongnu.org; Wed, 25 May 2016 01:28:24 -0400 Received: by mail-lb0-x22e.google.com with SMTP id h1so11908953lbj.3 for ; Tue, 24 May 2016 22:28:24 -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=poVyxVe1tPOiGKQbUbzMVxlZKhgvSGPNj+2ZC47oUvQ=; b=TFDyXucyea5c8xLdUgWWIGkzYVLZGC6ijOFignPVljsTAPesDoKUxmbPiKwG2znsSQ npep4oqhPb68790w/tjUoRA+yPQGW1itnTDIQW2IRjhjMxdf1XcdC8ZbIpZRL9ute/ty /z1RY6dLWlMsUkgyUVrYgwuStFpoadhTF68RE= 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=poVyxVe1tPOiGKQbUbzMVxlZKhgvSGPNj+2ZC47oUvQ=; b=W2TGbQSXJ5tJF2vlrwzIGmTvI3tMBQKCi6mnVgyLBCiAO3VS5CaQUxSuCa1ojGS1Xr wk1S/k5SBv79muLExY1TxcWi0bnTuC092CgqHCGPR2R6gXtvun1DRsxj5hKC/X+gJumb YZG6QRVggH28eRbx2WSdp+wW3B+bMcsjbt4TZPWOi073k1aDzXdBpVOmfIxrZMD30/8p PVXk9BcClL2iohxbm32Joaa/uAMco5Yt98KnVCeG1Tn8NacnmYS/ac6YkY/cNeFy4YE6 LkC62QWIwkUvzDkBeqYM4U6hgjnHNPGX3HDQGGHkGITUNlZpHWHxFLwfXmW8bycyWxhG Dn0w== X-Gm-Message-State: ALyK8tLk4N6UL6GUyA558ZtzN9kwKx/oEiZaGIlAwxzgX0zuQWVjjVKnmjjhJzTw3SPlP8/5 X-Received: by 10.112.73.40 with SMTP id i8mr510100lbv.101.1464154103129; Tue, 24 May 2016 22:28:23 -0700 (PDT) Received: from beaming.home (91-157-168-132.elisa-laajakaista.fi. [91.157.168.132]) by smtp.gmail.com with ESMTPSA id g10sm1136823lbc.43.2016.05.24.22.28.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 24 May 2016 22:28:22 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Wed, 25 May 2016 08:27:33 +0300 Message-Id: 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:c04::22e Subject: [Qemu-devel] [PULL 01/38] linux-user: Check array bounds in errno conversion 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: Timothy E Baldwin Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Timothy E Baldwin Check array bounds in host_to_target_errno() and target_to_host_errno(). Signed-off-by: Timothy Edward Baldwin Message-id: 1441497448-32489-2-git-send-email-T.E.Baldwin99@members.leeds.ac.uk [PMM: Add a lower-bound check, use braces on if(), tweak commit message] Signed-off-by: Peter Maydell Signed-off-by: Riku Voipio Reviewed-by: Laurent Vivier --- linux-user/syscall.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 032d338..5246f36 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -619,15 +619,19 @@ static uint16_t host_to_target_errno_table[ERRNO_TABLE_SIZE] = { static inline int host_to_target_errno(int err) { - if(host_to_target_errno_table[err]) + if (err >= 0 && err < ERRNO_TABLE_SIZE && + host_to_target_errno_table[err]) { return host_to_target_errno_table[err]; + } return err; } static inline int target_to_host_errno(int err) { - if (target_to_host_errno_table[err]) + if (err >= 0 && err < ERRNO_TABLE_SIZE && + target_to_host_errno_table[err]) { return target_to_host_errno_table[err]; + } return err; }