ath6kl: use a larger buffer for debug output
Subsystems (2)
PATCH 1/1 ath6kl: use a larger buffer for debug output
This function makes the static checkers grumble. The return value of snprintf() is the number of bytes which would have been copied if there was enough space. In theory, a %u can take take 10 digits so len could be larger than 16 and it would be a small information leak.
We may as well make the buffer larger as well since that is very easy to do.
drivers/net/wireless/ath/ath6kl/debug.c +2 -1
@@ -1551,11 +1551,12 @@ static ssize_t ath6kl_listen_int_read(struct file *file, size_t count, loff_t *ppos) { struct ath6kl *ar = file->private_data; -char buf[16 ]; +char buf[32 ];int len; len =snprintf (buf,sizeof (buf),"%u %u\n" , ar->listen_intvl_t, ar->listen_intvl_b); + len =min (sizeof (buf), len);return simple_read_from_buffer (user_buf, count, ppos, buf, len); }
Quoted 16 lines · Dan Carpenter
This function makes the static checkers grumble. The return value of
snprintf()is the number of bytes which would have been copied if there was enough space. In theory, a %u can take take 10 digits so len could be larger than 16 and it would be a small information leak.We may as well make the buffer larger as well since that is very easy to do.
Signed-off-by Dan Carpenter <[email protected]>drivers/net/wireless/ath/ath6kl/debug.c +0
-0
drivers/net/wireless/ath/ath6kl/debug.c static ssize_t ath6kl_listen_int_read(struct file *file, · line 1559
Quoted 10 lines
drivers/net/wireless/ath/ath6kl/debug.c +2
-1@@ -1551,11 +1551,12 @@ static ssize_t ath6kl_listen_int_read(struct file *file, size_t count, loff_t *ppos) { struct ath6kl *ar = file->private_data; -char buf[16 ]; +char buf[32 ];int len; len =snprintf (buf,sizeof (buf),"%u %u\n" , ar->listen_intvl_t, ar->listen_intvl_b); + len =min (sizeof (buf), len);
Maybe that should be scnprintf instead then?
johannes
Quoted 24 lines · Johannes Berg
Quoted 23 lines · Dan Carpenter
This function makes the static checkers grumble. The return value of
snprintf()is the number of bytes which would have been copied if there was enough space. In theory, a %u can take take 10 digits so len could be larger than 16 and it would be a small information leak.We may as well make the buffer larger as well since that is very easy to do.
Signed-off-by Dan Carpenter <[email protected]>drivers/net/wireless/ath/ath6kl/debug.c +1
-1@@ -1551,11 +1551,12 @@ static ssize_t ath6kl_listen_int_read(struct file *file, size_t count, loff_t *ppos) { struct ath6kl *ar = file->private_data; -char buf[16 ]; +char buf[32 ];int len;
Quoted 5 lines
drivers/net/wireless/ath/ath6kl/debug.c static ssize_t ath6kl_listen_int_read(struct file *file, · line 1559
Quoted 3 lines
drivers/net/wireless/ath/ath6kl/debug.c +1
-0len =snprintf (buf,sizeof (buf),"%u %u\n" , ar->listen_intvl_t, ar->listen_intvl_b); + len =min (sizeof (buf), len);Maybe that should be scnprintf instead then?
Yeah, I agree. And most likely debug.c has even more cases where scnprintf() is needed.
Kalle
Quoted 9 lines · Kalle Valo
Quoted 5 lines
drivers/net/wireless/ath/ath6kl/debug.c static ssize_t ath6kl_listen_int_read(struct file *file, · line 1559
Quoted 3 lines
drivers/net/wireless/ath/ath6kl/debug.c +1
-0len =snprintf (buf,sizeof (buf),"%u %u\n" , ar->listen_intvl_t, ar->listen_intvl_b); + len =min (sizeof (buf), len);Maybe that should be scnprintf instead then?
Yeah, I agree. And most likely
debug.chas even more cases wherescnprintf()is needed.
Yes yes. Obviously. I sent the patch at 5 pm on Friday and lost track of it for a bit. I'll send a fixed version tomorrow morning.
regards,
dan carpenter
PATCH v2 1/1 ath6kl: use a larger buffer for debug output
In reply to Johannes BergThe return value of snprintf() is the number of bytes which would have been copied if there was enough space, but we want the number of bytes actually copied. The scnprintf() function does this.
Also in theory, a %u can take take 10 digits so we may as well make the buffer larger as well.
---
v2: I didn't know about the scnprintf() function before. Thanks Johannes.
drivers/net/wireless/ath/ath6kl/debug.c +2 -2
@@ -1551,10 +1551,10 @@ static ssize_t ath6kl_listen_int_read(struct file *file, size_t count, loff_t *ppos) { struct ath6kl *ar = file->private_data; -char buf[16 ]; +char buf[32 ];int len; - len =snprintf (buf,sizeof (buf),"%u %u\n" , ar->listen_intvl_t, + len =scnprintf (buf,sizeof (buf),"%u %u\n" , ar->listen_intvl_t, ar->listen_intvl_b);return simple_read_from_buffer (user_buf, count, ppos, buf, len);
Kalle Valo
AppliedQuoted 8 lines · Dan Carpenter
The return value of
snprintf()is the number of bytes which would have been copied if there was enough space, but we want the number of bytes actually copied. Thescnprintf()function does this.Also in theory, a %u can take take 10 digits so we may as well make the buffer larger as well.
Signed-off-by Dan Carpenter <[email protected]>
Thanks, applied.
Quoted 2 lines
v2: I didn't know about the
scnprintf()function before. Thanks Johannes.
Me neither, so thank you from me as well :)
Kalle