diff options
author | Solomon Peachy <pizza@shaftnet.org> | 2021-08-06 09:56:22 -0400 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2021-08-06 10:08:00 -0400 |
commit | 835d0c737a7e04f30b3990249ce461999ea2cf3a (patch) | |
tree | d634553bc578af54cfc6f14ac24a59251a60b7a7 | |
parent | da45b37fac6d0d711cdafa0c73eabdc47e8c6a8b (diff) | |
download | rockbox-835d0c737a7e04f30b3990249ce461999ea2cf3a.tar.gz rockbox-835d0c737a7e04f30b3990249ce461999ea2cf3a.zip |
logf: Fix two issues with logf_panic_dump()
* It had a (read) buffer overflow when dumping the stuff on the back half of the buffer
* a highly questionable code construct was nuked
Change-Id: I7f6f119524fc2095f788fc9b3d356459955d3ace
-rw-r--r-- | firmware/export/logf.h | 2 | ||||
-rw-r--r-- | firmware/logf.c | 11 |
2 files changed, 9 insertions, 4 deletions
diff --git a/firmware/export/logf.h b/firmware/export/logf.h index c8aaad06b4..7fbe5976a4 100644 --- a/firmware/export/logf.h +++ b/firmware/export/logf.h | |||
@@ -31,7 +31,7 @@ | |||
31 | 31 | ||
32 | #define MAX_LOGF_SIZE 16384 | 32 | #define MAX_LOGF_SIZE 16384 |
33 | 33 | ||
34 | extern unsigned char logfbuffer[MAX_LOGF_SIZE]; | 34 | extern unsigned char logfbuffer[MAX_LOGF_SIZE + 1]; |
35 | extern int logfindex; | 35 | extern int logfindex; |
36 | extern bool logfwrap; | 36 | extern bool logfwrap; |
37 | extern bool logfenabled; | 37 | extern bool logfenabled; |
diff --git a/firmware/logf.c b/firmware/logf.c index 11ffa4e15c..e71425f2c3 100644 --- a/firmware/logf.c +++ b/firmware/logf.c | |||
@@ -61,7 +61,7 @@ static int logdiskfindex; | |||
61 | #ifdef ROCKBOX_HAS_LOGF | 61 | #ifdef ROCKBOX_HAS_LOGF |
62 | 62 | ||
63 | #ifndef __PCTOOL__ | 63 | #ifndef __PCTOOL__ |
64 | unsigned char logfbuffer[MAX_LOGF_SIZE]; | 64 | unsigned char logfbuffer[MAX_LOGF_SIZE + 1]; |
65 | int logfindex; | 65 | int logfindex; |
66 | bool logfwrap; | 66 | bool logfwrap; |
67 | bool logfenabled = true; | 67 | bool logfenabled = true; |
@@ -272,10 +272,14 @@ void logf_panic_dump(int *y) | |||
272 | return; | 272 | return; |
273 | } | 273 | } |
274 | 274 | ||
275 | /* Explicitly null-terminate our buffer */ | ||
276 | logfbuffer[MAX_LOGF_SIZE] = 0; | ||
277 | |||
275 | lcd_puts(1, (*y)++, "start of logf data"); | 278 | lcd_puts(1, (*y)++, "start of logf data"); |
276 | lcd_update(); | 279 | lcd_update(); |
277 | i = logfindex - 2; /* The last actual characer (i.e. not '\0') */ | ||
278 | 280 | ||
281 | /* The intent is to dump the newest log entries first! */ | ||
282 | i = logfindex - 2; /* The last actual characer (i.e. not '\0') */ | ||
279 | while(i >= 0) | 283 | while(i >= 0) |
280 | { | 284 | { |
281 | while(logfbuffer[i] != 0 && i>=0) | 285 | while(logfbuffer[i] != 0 && i>=0) |
@@ -300,12 +304,13 @@ void logf_panic_dump(int *y) | |||
300 | } | 304 | } |
301 | if(strlen( &logfbuffer[i + 1]) > 0) | 305 | if(strlen( &logfbuffer[i + 1]) > 0) |
302 | { | 306 | { |
303 | lcd_putsf(1, (*y)++, "%*s", (MAX_LOGF_SIZE-i) &logfbuffer[i + 1]); | 307 | lcd_putsf(1, (*y)++, "%*s", &logfbuffer[i + 1]); |
304 | lcd_update(); | 308 | lcd_update(); |
305 | } | 309 | } |
306 | } | 310 | } |
307 | i--; | 311 | i--; |
308 | } | 312 | } |
313 | |||
309 | lcd_puts(1, (*y)++, "end of logf data"); | 314 | lcd_puts(1, (*y)++, "end of logf data"); |
310 | lcd_update(); | 315 | lcd_update(); |
311 | } | 316 | } |