Net: rxrpc: signed and unsigned issue, need type cast for n_elem.
Subsystems (3)
PATCH 1/1 Net: rxrpc: signed and unsigned issue, need type cast for n_elem.
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
--- net/rxrpc/ar-key.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
net/rxrpc/ar-key.c +1 -1
@@ -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 ) {
Signature · 1 line
1.7.7.6
Quoted 17 lines · Chen Gang
n_elemis 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 <[email protected]>--- net/rxrpc/ar-key.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)net/rxrpc/ar-key.c +0
-0
net/rxrpc/ar-key.c static int rxrpc_krb5_decode_tagged_array(struct krb5_tagged_data **_td, · line 349
Quoted 5 lines
net/rxrpc/ar-key.c +1
-1@@ -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.
Quoted 3 lines
net/rxrpc/ar-key.c +0
-0return -EINVAL ; *_n_elem = n_elem;if (n_elem >0 ) {
Signature · 3 lines
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.
Quoted 19 lines · Ben Hutchings
Quoted 18 lines · Chen Gang
n_elemis 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 <[email protected]>--- net/rxrpc/ar-key.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)net/rxrpc/ar-key.c +0
-0@@ -346,7 +346,7 @@ static int rxrpc_krb5_decode_tagged_array(struct krb5_tagged_data **_td,
Quoted 8 lines
net/rxrpc/ar-key.c static int rxrpc_krb5_decode_tagged_array(struct krb5_tagged_data **_td, · line 349
Quoted 4 lines
net/rxrpc/ar-key.c +1
-1n_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 thenn_elem>max_n_elem(becausemax_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------------------------------------------------
net/rxrpc/ar-key.c +1 -1
@@ -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--------------------------------------------------
Quoted 6 lines
Ben.
Quoted 3 lines
net/rxrpc/ar-key.c +0
-0return -EINVAL ; *_n_elem = n_elem;if (n_elem >0 ) {
Signature · 3 lines
Chen Gang Asianux Corporation