staging: fbtft: fix out of bound access
Subsystems (2)
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
@@ -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
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.
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
Quoted 12 lines · Sudip Mukherjee
size of str is 16, but in snprintf the size was mentioned as 128.
Signed-off-by Sudip Mukherjee <[email protected]>--- drivers/staging/fbtft/fbtft-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)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 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
Quoted 5 lines · Dan Carpenter
Quoted 4 lines · Sudip Mukherjee
size of str is 16, but in snprintf the size was mentioned as 128.
Signed-off-by Sudip Mukherjee <[email protected]>---
<snip>
Quoted 1 line
Good eye. How did you find this?
:) not me. cppcheck.
Quoted 4 lines
The good news is buf[j] is <=
0xFFFFso 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