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: 529111 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 BD3091402A8 for ; Tue, 13 Oct 2015 00:45:38 +1100 (AEDT) Received: from localhost ([::1]:55452 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZldQ0-00030Z-Ip for incoming@patchwork.ozlabs.org; Mon, 12 Oct 2015 09:45:36 -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-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; bh=sXYlqjyCywPMEKVwkOnvLLRG7bH0yooCb7Xttt3/yC8=; b=LfCv01o2GtPXG858/h1WPVPuFjtcJ8YDtX0sW68r1B7X4AO3FwaDs4NkRezZwRbNLy PWD6YD8bCbOSZmp4FmOCVRvB9T5rqBWVMblhAChdUsIpE7buNw7fdbLJwTV/Rlofn/Jg AGwiRv/RAszhZu4mwGeyvikrkGbe4DfrSTUjPtSD3wobw8BIAjKVrUdxCaSPk+ahoFUe fPVE9wl2v1y5bNVYr2UfnjfTHXd6dd411+QLXbUQfiJm1GGJxZi/AFa52t21Vzvuvm71 TDKQAXyBtMBcpO/5TjjD+lU1ULDRLQcR6BfdqXj5uJ3+x/QjxIAk5EWZWP9LFF+ZLwk0 J0LA== X-Gm-Message-State: ALoCoQmMMhin2HAzmKD6J97Xfi3tDO+A7BfXVPsEgQSmAz+UTnCEoxF8S/s8tchVc4BSeos2WvUZ 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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; }