From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754196AbbCBOQV (ORCPT ); Mon, 2 Mar 2015 09:16:21 -0500 Received: from mail-la0-f49.google.com ([209.85.215.49]:40173 "EHLO mail-la0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753097AbbCBOQT (ORCPT ); Mon, 2 Mar 2015 09:16:19 -0500 Message-ID: <54F470AF.6050401@cogentembedded.com> Date: Mon, 02 Mar 2015 17:16:15 +0300 From: Sergei Shtylyov User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Jan Kasprzak CC: Ameen Ali , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] cosa.c : Array index 'i' is used before limits check. References: <1424807546-10013-1-git-send-email-ameenali023@gmail.com> <54ECD78F.7040607@cogentembedded.com> <20150302130652.GX19534@fi.muni.cz> In-Reply-To: <20150302130652.GX19534@fi.muni.cz> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello. On 3/2/2015 4:06 PM, Jan Kasprzak wrote: > : >avoid out-of-bounds-read by checking count before indexing. > : > : >Signed-off-by: Ameen Ali > : >--- > : > drivers/net/wan/cosa.c | 2 +- > : > 1 file changed, 1 insertion(+), 1 deletion(-) > : > : >diff --git a/drivers/net/wan/cosa.c b/drivers/net/wan/cosa.c > : >index 83c39e2..5252e21 100644 > : >--- a/drivers/net/wan/cosa.c > : >+++ b/drivers/net/wan/cosa.c > : >@@ -376,7 +376,7 @@ static int __init cosa_init(void) > : > } > : > for (i=0; i : > cosa_cards[i].num = -1; > : >- for (i=0; io[i] != 0 && i < MAX_CARDS; i++) > : >+ for (i=0; (i < MAX_CARDS) && (io[i] != 0) ; i++) > : Parens you've added aren't necessary. > Yes, but I am OK with both variants. Anyway, space before ; should be removed (just noticed). > : I suggest to add spaces after and before = in the first expression. > In that case, also the upper for() cycle should be modified > to match this. I don't think this is necessary. As long as it doesn't cause complaints from scripts/checkpatch.pl... > -Yenya WBR, Sergei