* [PATCH] Net: rxrpc: signed and unsigned issue, need type cast for n_elem.
@ 2013-04-22 10:24 Chen Gang
2013-04-22 19:34 ` Ben Hutchings
0 siblings, 1 reply; 3+ messages in thread
From: Chen Gang @ 2013-04-22 10:24 UTC (permalink / raw)
To: David Miller, dhowells@redhat•com, Eric W. Biederman,
Rusty Russell, Serge Hallyn
Cc: netdev
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)
return -EINVAL;
*_n_elem = n_elem;
if (n_elem > 0) {
--
1.7.7.6
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Net: rxrpc: signed and unsigned issue, need type cast for n_elem.
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
0 siblings, 1 reply; 3+ messages in thread
From: Ben Hutchings @ 2013-04-22 19:34 UTC (permalink / raw)
To: Chen Gang
Cc: David Miller, dhowells@redhat•com, Eric W. Biederman,
Rusty Russell, Serge Hallyn, netdev
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).
Ben.
> return -EINVAL;
> *_n_elem = n_elem;
> if (n_elem > 0) {
--
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Net: rxrpc: signed and unsigned issue, need type cast for n_elem.
2013-04-22 19:34 ` Ben Hutchings
@ 2013-04-23 1:24 ` Chen Gang
0 siblings, 0 replies; 3+ messages in thread
From: Chen Gang @ 2013-04-23 1:24 UTC (permalink / raw)
To: Ben Hutchings
Cc: David Miller, dhowells@redhat•com, Eric W. Biederman,
Rusty Russell, Serge Hallyn, netdev
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-04-23 1:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox