public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Chen Gang <gang.chen@asianux•com>
To: Ben Hutchings <bhutchings@solarflare•com>
Cc: David Miller <davem@davemloft•net>,
	"dhowells@redhat•com" <dhowells@redhat•com>,
	"Eric W. Biederman" <ebiederm@xmission•com>,
	Rusty Russell <rusty@rustcorp•com.au>,
	Serge Hallyn <serge.hallyn@canonical•com>,
	netdev <netdev@vger•kernel.org>
Subject: Re: [PATCH] Net: rxrpc: signed and unsigned issue, need type cast for n_elem.
Date: Tue, 23 Apr 2013 09:24:48 +0800	[thread overview]
Message-ID: <5175E2E0.1030901@asianux.com> (raw)
In-Reply-To: <1366659281.4016.7.camel@bwh-desktop.uk.solarflarecom.com>

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 <gang.chen@asianux•com>
>> ---
>>  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 --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) {

----------------------diff end--------------------------------------------------

> Ben.
> 
>>  		return -EINVAL;
>>  	*_n_elem = n_elem;
>>  	if (n_elem > 0) {
> 


-- 
Chen Gang

Asianux Corporation

      reply	other threads:[~2013-04-23  1:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-22 10:24 [PATCH] Net: rxrpc: signed and unsigned issue, need type cast for n_elem Chen Gang
2013-04-22 19:34 ` Ben Hutchings
2013-04-23  1:24   ` Chen Gang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5175E2E0.1030901@asianux.com \
    --to=gang.chen@asianux$(echo .)com \
    --cc=bhutchings@solarflare$(echo .)com \
    --cc=davem@davemloft$(echo .)net \
    --cc=dhowells@redhat$(echo .)com \
    --cc=ebiederm@xmission$(echo .)com \
    --cc=netdev@vger$(echo .)kernel.org \
    --cc=rusty@rustcorp$(echo .)com.au \
    --cc=serge.hallyn@canonical$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox