Skip to contentSkip to conversation

staging: fbtft: fix out of bound access

PATCH Superseded Sudip Mukherjee 3 participants 5 messages Jun 4, 2015

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: fbtft: fix out of bound access

size of str is 16, but in snprintf the size was mentioned as 128.

---
 drivers/staging/fbtft/fbtft-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/fbtft/fbtft-core.c +1 -1
index ce64521..0af84b5 100644
@@ -1096,7 +1096,7 @@ static int fbtft_init_display_dt(struct fbtft_par *par)
 			/* make debug message */
 			msg[0] = '\0';
 			for (j = 0; j < i; j++) {
-				snprintf(str, 128, " %02X", buf[j]);
+				snprintf(str, 16, " %02X", buf[j]);
 				strcat(msg, str);
 			}
 			fbtft_par_dbg(DEBUG_INIT_DISPLAY, par,
Signature · 1 line
1.8.1.2
#1 lore raw
Quoted 1 line · Sudip Mukherjee

size of str is 16, but in snprintf the size was mentioned as 128.

[]

drivers/staging/fbtft/fbtft-core.c

Quoted 1 line
drivers/staging/fbtft/fbtft-core.c +0 -0

[]

drivers/staging/fbtft/fbtft-core.c static int fbtft_init_display_dt(struct fbtft_par *par) · line 1099

Quoted 6 lines
drivers/staging/fbtft/fbtft-core.c +1 -1
@@ -1096,7 +1096,7 @@ static int fbtft_init_display_dt(struct fbtft_par *par)
 			/* make debug message */
 			msg[0] = '\0';
 			for (j = 0; j < i; j++) {
-				snprintf(str, 128, " %02X", buf[j]);
+				snprintf(str, 16, " %02X", buf[j]);

using sizeof(str) is probably more robust

msg isn't big enough to hold the maximum possible output.

If this is really useful, and I rather doubt it is, it'd probably be better to use a loop to output multiple lines, one for each register.

#2 lore raw
Quoted 14 lines · Joe Perches
Quoted 1 line · Sudip Mukherjee

size of str is 16, but in snprintf the size was mentioned as 128.

[]

drivers/staging/fbtft/fbtft-core.c

Quoted 1 line
drivers/staging/fbtft/fbtft-core.c +0 -0

[]

drivers/staging/fbtft/fbtft-core.c static int fbtft_init_display_dt(struct fbtft_par *par) · line 1099

Quoted 6 lines
drivers/staging/fbtft/fbtft-core.c +1 -1
@@ -1096,7 +1096,7 @@ static int fbtft_init_display_dt(struct fbtft_par *par)
 			/* make debug message */
 			msg[0] = '\0';
 			for (j = 0; j < i; j++) {
-				snprintf(str, 128, " %02X", buf[j]);
+				snprintf(str, 16, " %02X", buf[j]);

using sizeof(str) is probably more robust

Quoted 1 line

msg isn't big enough to hold the maximum possible output.

yes, it will not hold. i didn't notice msg size.

Quoted 4 lines

If this is really useful, and I rather doubt it is, it'd probably be better to use a loop to output multiple lines, one for each register.

I will send in a v2 doing this.

regards
sudip

Quoted 2 lines
#3 lore raw
In reply to Sudip Mukherjee
Quoted 12 lines · Sudip Mukherjee

size of str is 16, but in snprintf the size was mentioned as 128.

---
 drivers/staging/fbtft/fbtft-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/fbtft/fbtft-core.c +0 -0
index ce64521..0af84b5 100644

drivers/staging/fbtft/fbtft-core.c static int fbtft_init_display_dt(struct fbtft_par *par) · line 1099

Quoted 5 lines
drivers/staging/fbtft/fbtft-core.c +1 -1
@@ -1096,7 +1096,7 @@ static int fbtft_init_display_dt(struct fbtft_par *par)
 			/* make debug message */
 			msg[0] = '\0';
 			for (j = 0; j < i; j++) {
-				snprintf(str, 128, " %02X", buf[j]);
+				snprintf(str, 16, " %02X", buf[j]);

Good eye. How did you find this?

The good news is buf[j] is <= 0xFFFF so it won't actually overflow. Who knows why it is zero padded 2 spaces... But use sizeof(str) instead of 16.

regards,
dan carpenter

#4 lore raw
Quoted 5 lines · Dan Carpenter
Quoted 4 lines · Sudip Mukherjee

size of str is 16, but in snprintf the size was mentioned as 128.

---

<snip>

Quoted 1 line

Good eye. How did you find this?

:) not me. cppcheck.

Quoted 4 lines

The good news is buf[j] is <= 0xFFFF so it won't actually overflow. Who knows why it is zero padded 2 spaces... But use sizeof(str) instead of 16.

but my v2 will remove the use of msg and str.

regards
sudip

Quoted 4 lines

regards,
dan carpenter