Skip to contentSkip to conversation

ath6kl: use a larger buffer for debug output

PATCH Superseded Dan Carpenter 3 participants 6 messages Nov 18, 2011 – Nov 24, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index 9eff0d0..e632008 100644
@@ -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);
 }
#1 lore raw
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.

drivers/net/wireless/ath/ath6kl/debug.c +0 -0
index 9eff0d0..e632008 100644

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

#2 lore raw
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.

drivers/net/wireless/ath/ath6kl/debug.c +1 -1
index 9eff0d0..e632008 100644
@@ -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 -0
 	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?

Yeah, I agree. And most likely debug.c has even more cases where scnprintf() is needed.

Kalle

#3 lore raw
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 -0
 	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?

Yeah, I agree. And most likely debug.c has even more cases where scnprintf() 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

#4 lore raw

PATCH v2 1/1 ath6kl: use a larger buffer for debug output

In reply to Johannes Berg

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. 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
index 9eff0d0..eb808b4 100644
@@ -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);
Applied
#5 lore raw
Quoted 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. 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.

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