From patchwork Fri May 27 12:59:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 9138305 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 C033A60759 for ; Fri, 27 May 2016 13:01:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B229C27CF9 for ; Fri, 27 May 2016 13:01:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A713E28135; Fri, 27 May 2016 13:01:26 +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 02DFA27CF9 for ; Fri, 27 May 2016 13:01:24 +0000 (UTC) Received: from localhost ([::1]:45692 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6HOF-0007If-4J for patchwork-qemu-devel@patchwork.kernel.org; Fri, 27 May 2016 09:01:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37121) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6HNZ-0007Ed-Nt for qemu-devel@nongnu.org; Fri, 27 May 2016 09:00:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b6HNU-00014q-1m for qemu-devel@nongnu.org; Fri, 27 May 2016 09:00:40 -0400 Received: from mail-lf0-x22a.google.com ([2a00:1450:4010:c07::22a]:36601) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6HNS-00014T-D8 for qemu-devel@nongnu.org; Fri, 27 May 2016 09:00:35 -0400 Received: by mail-lf0-x22a.google.com with SMTP id b73so23100936lfb.3 for ; Fri, 27 May 2016 06:00:34 -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=kctXY1p+drLI4agkULYRFJ0Rog3feD+gJXZGg7NxQ4l+PbUml2pDwqa1dEIAbVaPbe hRY1Js+5ABg4vBqmO79cr+9npReM/Johk5Zv3ELm0Iw3mxAeHTtoqeV8f3GqmUGbbecs suUeMnMmlvis0q30C050Alx0MI8FgfnnuL04s= 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=RAiryTH1Wgh1p1Scwh/5HFGLmZlNALIxqDodq0vXYgf2RO6NKAAN5o38FydYjp9kY2 jTUVyHp4kt42dNAqEl5McNylXzFQs3ogQjPCjrj5DEGehem9MhQp0FIYx6IvziM3U8rk cx045U+Ed5TgSXuCct8i91Xh+eJ3jJhF1MqygLvEACk3En61PHE6AXrWrs/1bnSQAX2U LasgaM5yTVhuqjxNM/T5dILn72CMnpV8o3/ty94Tsaxt1KShSrVh4qyqbqlqWZo0PotQ N9vUHZW3kITuEis0VL2bG24v4TpTMP2dP/kgH5iFIFF8zqJ72ocN86gAIp1fwTFF838I 5PZg== X-Gm-Message-State: ALyK8tJsU2KuV46J35Nmm9hMLLUuC6PV/+J9UXSL1xicBZwIg9lA8yDqhxHD85UDoctFFbuP X-Received: by 10.25.160.85 with SMTP id j82mr4326497lfe.52.1464354033411; Fri, 27 May 2016 06:00:33 -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.00.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 May 2016 06:00:32 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Fri, 27 May 2016 15:59:52 +0300 Message-Id: <2466119c9551d606a0f92f9832e0c865bc04b488.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::22a Subject: [Qemu-devel] [PULL v2 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; }