From patchwork Mon Oct 12 13:42:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 54756 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by patches.linaro.org (Postfix) with ESMTPS id 1F88522DB6 for ; Mon, 12 Oct 2015 13:46:11 +0000 (UTC) Received: by lbwr8 with SMTP id r8sf69852661lbw.0 for ; Mon, 12 Oct 2015 06:46:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:cc:subject:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list; bh=sXYlqjyCywPMEKVwkOnvLLRG7bH0yooCb7Xttt3/yC8=; b=HXi4EGRRIYD4PzN+yw5qWp8BVXrQ5BQriY0hBTIwzg8MqWRRXTbvSdLC1QEVZ6izhJ AuN/EgRg2WfsiK+c5kqZ/sU6VA/MT7qSMj03jSrsUsnhA80JfdF3Tpo9PP1X+RH3tDBN lutC4MP5jfBg+Z3c0sKHqgxCnJbPlLtdj5zOJ0bnmiAqI9MFQHICfvz/bybdbk5b/9KW QDUb7hbnVXAUe8gbAhcsMQx/dPUqU0iTRm783o6IJEwmIK2Mlw/En6YD7OhMRdabsV1G IC56uoK/bCJCDewou09DCQ8XNDnHPBHQP/2FGEzq0dW3Hfvis3IEkiNqZ4c268SwjFYL Elyg== X-Gm-Message-State: ALoCoQnTlcU5OzcV3t5w1zrs0ikNUo9x+l+H+T4L17X0VKVKqKDaDW2q046ExItDS/8hyEOLWyEX X-Received: by 10.112.151.9 with SMTP id um9mr5618451lbb.19.1444657569547; Mon, 12 Oct 2015 06:46:09 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.166.82 with SMTP id p79ls528238lfe.99.gmail; Mon, 12 Oct 2015 06:46:09 -0700 (PDT) X-Received: by 10.25.41.79 with SMTP id p76mr8318672lfp.16.1444657569401; Mon, 12 Oct 2015 06:46:09 -0700 (PDT) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id m82si11277813lfg.118.2015.10.12.06.46.09 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Oct 2015 06:46:09 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by lbwr8 with SMTP id r8so141971190lbw.2 for ; Mon, 12 Oct 2015 06:46:09 -0700 (PDT) X-Received: by 10.112.64.72 with SMTP id m8mr12145486lbs.41.1444657569161; Mon, 12 Oct 2015 06:46:09 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1559202lbq; Mon, 12 Oct 2015 06:46:08 -0700 (PDT) X-Received: by 10.140.19.49 with SMTP id 46mr15444589qgg.97.1444657568275; Mon, 12 Oct 2015 06:46:08 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 80si14935506qgj.40.2015.10.12.06.46.08 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 12 Oct 2015 06:46:08 -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; Received: from localhost ([::1]:55452 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZldQV-00030Z-Sx for patch@linaro.org; Mon, 12 Oct 2015 09:46:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32894) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZldNZ-0007zq-AW for qemu-devel@nongnu.org; Mon, 12 Oct 2015 09:43:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZldNS-0002Nr-9P for qemu-devel@nongnu.org; Mon, 12 Oct 2015 09:43:05 -0400 Received: from mail-lb0-f179.google.com ([209.85.217.179]:35340) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZldNS-0002NO-2u for qemu-devel@nongnu.org; Mon, 12 Oct 2015 09:42:58 -0400 Received: by lbwr8 with SMTP id r8so141876769lbw.2 for ; Mon, 12 Oct 2015 06:42:57 -0700 (PDT) X-Received: by 10.25.167.138 with SMTP id q132mr8164641lfe.15.1444657377074; Mon, 12 Oct 2015 06:42:57 -0700 (PDT) Received: from localhost.localdomain (91-157-196-38.elisa-laajakaista.fi. [91.157.196.38]) by smtp.gmail.com with ESMTPSA id jj4sm2886376lbc.14.2015.10.12.06.42.55 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 Oct 2015 06:42:56 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Mon, 12 Oct 2015 16:42:51 +0300 Message-Id: <1444657371-3891-1-git-send-email-riku.voipio@linaro.org> X-Mailer: git-send-email 2.6.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.217.179 Cc: Riku Voipio , Timothy Edward Baldwin Subject: [Qemu-devel] [PATCH] linux-user: Fix array bounds in errno conversion X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: riku.voipio@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Riku Voipio Check array bounds in host_to_target_errno() and target_to_host_errno(). Originally from Timothy Edward Baldwin, checks improved by Riku Cc: Timothy Edward Baldwin Signed-off-by: Riku Voipio --- linux-user/syscall.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 06a59b4..100a111 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -614,17 +614,19 @@ static uint16_t host_to_target_errno_table[ERRNO_TABLE_SIZE] = { #endif }; -static inline int host_to_target_errno(int err) +static inline unsigned int host_to_target_errno(unsigned int err) { - if(host_to_target_errno_table[err]) + if(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) +static inline unsigned int target_to_host_errno(unsigned int err) { - if (target_to_host_errno_table[err]) + if (err < ERRNO_TABLE_SIZE && target_to_host_errno_table[err]) { return target_to_host_errno_table[err]; + } return err; }