Staging: rtl8723bs: Check sscanf return value
PATCH 1/1 Staging: rtl8723bs: Check sscanf return value
Check the sscanf return value and handle it.
Issue found by checkpatch.pl.
WARNING: unchecked sscanf return value
--- drivers/staging/rtl8723bs/os_dep/ioctl_linux.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/staging/rtl8723bs/os_dep/ioctl_linux.c +9 -2
@@ -2355,7 +2355,11 @@ static int rtw_wx_read32(struct net_device *dev, bytes =0 ; addr =0 ; -sscanf (ptmp,"%d,%x" , &bytes, &addr); + ret =sscanf (ptmp,"%d,%x" , &bytes, &addr); +if (ret !=1 ) { + ret = -EINVAL ; + goto exit; + }switch (bytes) {case 1 :
@@ -2392,12 +2396,15 @@ static int rtw_wx_write32(struct net_device *dev,u32 addr;u32 data32;u32 bytes; +int ret; bytes =0 ; addr =0 ; data32 =0 ; -sscanf (extra,"%d,%x,%x" , &bytes, &addr, &data32); + ret =sscanf (extra,"%d,%x,%x" , &bytes, &addr, &data32); +if (ret !=1 ) +return -EINVAL ;switch (bytes) {case 1 :
Signature · 1 line
2.11.0
Quoted 1 line · Georgiana Chelu
Check the sscanf return value and handle it.
Why do you check for a return value of 1?
julia
Quoted 53 lines
Issue found by checkpatch.pl.
WARNING: unchecked sscanf return valueSigned-off-by Georgiana Chelu <[email protected]>--- drivers/staging/rtl8723bs/os_dep/ioctl_linux.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)drivers/staging/rtl8723bs/os_dep/ioctl_linux.c +9
-3@@ -2355,7 +2355,11 @@ static int rtw_wx_read32(struct net_device *dev, bytes =0 ; addr =0 ; -sscanf (ptmp,"%d,%x" , &bytes, &addr); + ret =sscanf (ptmp,"%d,%x" , &bytes, &addr); +if (ret !=1 ) { + ret = -EINVAL ; + goto exit; + }switch (bytes) {case 1 :@@ -2392,12 +2396,15 @@ static int rtw_wx_write32(struct net_device *dev,u32 addr;u32 data32;u32 bytes; +int ret; bytes =0 ; addr =0 ; data32 =0 ; -sscanf (extra,"%d,%x,%x" , &bytes, &addr, &data32); + ret =sscanf (extra,"%d,%x,%x" , &bytes, &addr, &data32); +if (ret !=1 ) +return -EINVAL ;switch (bytes) {case 1 : --2.11.0
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20170918212640.inn4in2kwsn2pzvr%40fireworks.
For more options, visit https://groups.google.com/d/optout.
Thanks for the review! I was thinking of the basic case with only one argument.
The sscanf function returns "the number of input items successfully matched and assigned" [1].
I will resend the patch, checking for value 2 (on the first fix) and 3 (on the second fix).
[1] https://linux.die.net/man/3/sscanf
Best regards,
Georgiana
Quoted 69 lines · Julia Lawall
Quoted 1 line · Georgiana Chelu
Check the sscanf return value and handle it.
Why do you check for a return value of 1?
julia
Review
Quoted 10 lines
Issue found by checkpatch.pl.
WARNING: unchecked sscanf return valueSigned-off-by Georgiana Chelu <[email protected]>--- drivers/staging/rtl8723bs/os_dep/ioctl_linux.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)(quoted diff) +0
-0
b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.cQuoted 36 lines
index
6a8f805c0b28..18aa4011a576100644drivers/staging/rtl8723bs/os_dep/ioctl_linux.c +9
-3@@ -2355,7 +2355,11 @@ static int rtw_wx_read32(struct net_device *dev, bytes =0 ; addr =0 ; -sscanf (ptmp,"%d,%x" , &bytes, &addr); + ret =sscanf (ptmp,"%d,%x" , &bytes, &addr); +if (ret !=1 ) { + ret = -EINVAL ; + goto exit; + }switch (bytes) {case 1 :@@ -2392,12 +2396,15 @@ static int rtw_wx_write32(struct net_device *dev,u32 addr;u32 data32;u32 bytes; +int ret; bytes =0 ; addr =0 ; data32 =0 ; -sscanf (extra,"%d,%x,%x" , &bytes, &addr, &data32); + ret =sscanf (extra,"%d,%x,%x" , &bytes, &addr, &data32); +if (ret !=1 ) +return -EINVAL ;switch (bytes) {case 1 : --2.11.0
Quoted 2 lines
--
You received this message because you are subscribed to the GoogleGroups "outreachy-kernel" group.
Quoted 1 line
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected].
Quoted 2 lines
To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/
msgid/outreachy-kernel/20170918212640.inn4in2kwsn2pzvr%40fireworks.
Quoted 2 lines
For more options, visit https://groups.google.com/d/optout.
Quoted 7 lines · Georgiana Chelu
Thanks for the review! I was thinking of the basic case with only one argument.
The sscanf function returns "the number of input items successfully matched and assigned" [1].I will resend the patch, checking for value 2 (on the first fix) and 3 (on the second fix).
Actually, when I was looking around in the kernel, the first example I came across made the same mistake :)
julia
Quoted 92 lines
[1] https://linux.die.net/man/3/sscanf
Best regards,
GeorgianaOn 19 September 2017 at 08:18, Julia Lawall <[email protected]> wrote:
On Tue, 19 Sep 2017, Georgiana Chelu wrote: > Check the sscanf return value and handle it. Why do you check for a return value of 1? julia > > Issue found by checkpatch.pl. > WARNING: unchecked sscanf return value > > Signed-off-by: Georgiana Chelu <[email protected]> > --- > drivers/staging/rtl8723bs/os_dep/ioctl_linux.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c > index 6a8f805c0b28..18aa4011a576 100644 > --- a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c > +++ b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c > @@ -2355,7 +2355,11 @@ static int rtw_wx_read32(struct net_device *dev, > > bytes = 0; > addr = 0; > - sscanf(ptmp, "%d,%x", &bytes, &addr); > + ret = sscanf(ptmp, "%d,%x", &bytes, &addr); > + if (ret != 1) { > + ret = -EINVAL; > + goto exit; > + } > > switch (bytes) { > case 1: > @@ -2392,12 +2396,15 @@ static int rtw_wx_write32(struct net_device *dev, > u32 addr; > u32 data32; > u32 bytes; > + int ret; > > > bytes = 0; > addr = 0; > data32 = 0; > - sscanf(extra, "%d,%x,%x", &bytes, &addr, &data32); > + ret = sscanf(extra, "%d,%x,%x", &bytes, &addr, &data32); > + if (ret != 1) > + return -EINVAL; > > switch (bytes) { > case 1: > -- > 2.11.0 >Quoted 2 lines
--
You received this message because you are subscribed to the GoogleGroups "outreachy-kernel" group.
Quoted 1 line
To unsubscribe from this group and stop receiving emails from it,
send an email to [email protected].
Quoted 1 line
To post to this group, send email to
Quoted 1 line
To view this discussion on the web visithttps://groups.google.com/d/msgid/outreachy-kernel/20170918212640.inn4in2kw
sn2pzvr%40fireworks.
Quoted 2 lines
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visithttps://groups.google.com/d/msgid/outreachy-kernel/CALta04wPg7EUimMO0SX7_di EP%3Dm4URFs4n%3DUC20%2B8X1JDRjcqw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.