Skip to contentSkip to conversation

Staging: rtl8723bs: Check sscanf return value

PATCH Superseded Georgiana Chelu 2 participants 4 messages Sep 18, 2017 – Sep 19, 2017 Staging

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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
index 6a8f805c0b28..18aa4011a576 100644
@@ -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
#1 lore raw
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 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 -3
index 6a8f805c0b28..18aa4011a576 100644
@@ -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.

#2 lore raw

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 value

---
 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.c

Quoted 36 lines

index 6a8f805c0b28..18aa4011a576 100644

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

Quoted 2 lines

--
You received this message because you are subscribed to the Google

Groups "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.

#3 lore raw
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,
Georgiana

On 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 Google

Groups "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

[email protected].

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.