From patchwork Tue Apr 23 01:24:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chen Gang X-Patchwork-Id: 238704 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id AC1772C00C0 for ; Tue, 23 Apr 2013 11:25:56 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753946Ab3DWBZj (ORCPT ); Mon, 22 Apr 2013 21:25:39 -0400 Received: from intranet.asianux.com ([58.214.24.6]:36307 "EHLO intranet.asianux.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753913Ab3DWBZh (ORCPT ); Mon, 22 Apr 2013 21:25:37 -0400 Received: by intranet.asianux.com (Postfix, from userid 103) id 30FD218402F0; Tue, 23 Apr 2013 09:25:34 +0800 (CST) X-Spam-Score: -100.8 X-Spam-Checker-Version: SpamAssassin 3.1.9 (2007-02-13) on intranet.asianux.com X-Spam-Level: X-Spam-Status: No, score=-100.8 required=5.0 tests=AWL,BAYES_00, RATWARE_GECKO_BUILD,USER_IN_WHITELIST autolearn=no version=3.1.9 Received: from [10.1.0.143] (unknown [219.143.36.82]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by intranet.asianux.com (Postfix) with ESMTP id AD08C1840242; Tue, 23 Apr 2013 09:25:33 +0800 (CST) Message-ID: <5175E2E0.1030901@asianux.com> Date: Tue, 23 Apr 2013 09:24:48 +0800 From: Chen Gang User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: Ben Hutchings CC: David Miller , "dhowells@redhat.com" , "Eric W. Biederman" , Rusty Russell , Serge Hallyn , netdev Subject: Re: [PATCH] Net: rxrpc: signed and unsigned issue, need type cast for n_elem. References: <51750FC0.8000603@asianux.com> <1366659281.4016.7.camel@bwh-desktop.uk.solarflarecom.com> In-Reply-To: <1366659281.4016.7.camel@bwh-desktop.uk.solarflarecom.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On 2013年04月23日 03:34, Ben Hutchings wrote: > On Mon, 2013-04-22 at 18:24 +0800, Chen Gang wrote: >> n_elem is unsigned int which never < 0. >> but it seems, we realy need check it whether < 0. >> so need a type cast for it. >> >> find it by EXTRA_CFLAGS=-W >> >> >> Signed-off-by: Chen Gang >> --- >> net/rxrpc/ar-key.c | 2 +- >> 1 files changed, 1 insertions(+), 1 deletions(-) >> >> diff --git a/net/rxrpc/ar-key.c b/net/rxrpc/ar-key.c >> index 7633a75..ba0b722 100644 >> --- a/net/rxrpc/ar-key.c >> +++ b/net/rxrpc/ar-key.c >> @@ -346,7 +346,7 @@ static int rxrpc_krb5_decode_tagged_array(struct krb5_tagged_data **_td, >> >> n_elem = ntohl(*xdr++); >> toklen -= 4; >> - if (n_elem < 0 || n_elem > max_n_elem) >> + if ((int)n_elem < 0 || n_elem > max_n_elem) > > (int)n_elem < 0 is equivalent to n_elem >= 0x80000000, and if that is > true then n_elem > max_n_elem (because max_n_elem <= 0xff). > ok, thanks, my subject and the comments are incorrect. but I still prefer to improve the original code like below. (also need change the subject and the comments) ----------------------diff begin------------------------------------------------ ----------------------diff end-------------------------------------------------- > Ben. > >> return -EINVAL; >> *_n_elem = n_elem; >> if (n_elem > 0) { > diff --git a/net/rxrpc/ar-key.c b/net/rxrpc/ar-key.c index 7633a75..cde682f 100644 --- a/net/rxrpc/ar-key.c +++ b/net/rxrpc/ar-key.c @@ -346,7 +346,7 @@ static int rxrpc_krb5_decode_tagged_array(struct krb5_tagged_data **_td, n_elem = ntohl(*xdr++); toklen -= 4; - if (n_elem < 0 || n_elem > max_n_elem) + if (n_elem > max_n_elem) return -EINVAL; *_n_elem = n_elem; if (n_elem > 0) {