From: notaz Date: Thu, 29 Aug 2013 22:35:47 +0000 (+0300) Subject: fix array-out-of-bounds issue X-Git-Tag: v1.85~2^2~4 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cfae1ae17956a94d7deae336ce6b9571b3f825f1;p=picodrive.git fix array-out-of-bounds issue --- diff --git a/pico/state.c b/pico/state.c index a3695970..f9a7f839 100644 --- a/pico/state.c +++ b/pico/state.c @@ -180,7 +180,7 @@ typedef enum { CHUNK_CARTHW_ = CHUNK_CARTHW, // 64 (defined in PicoInt) } chunk_name_e; -static const char * const chunk_names[] = { +static const char * const chunk_names[CHUNK_DEFAULT_COUNT] = { "INVALID!", "M68K state", "RAM", @@ -237,7 +237,7 @@ static int write_chunk(chunk_name_e name, int len, void *data, void *file) } #define CHECKED_WRITE(name,len,data) { \ - if (PicoStateProgressCB && name < CHUNK_DEFAULT_COUNT) { \ + if (PicoStateProgressCB && name < CHUNK_DEFAULT_COUNT && chunk_names[name]) { \ strncpy(sbuff + 9, chunk_names[name], sizeof(sbuff) - 9); \ PicoStateProgressCB(sbuff); \ } \ @@ -245,7 +245,7 @@ static int write_chunk(chunk_name_e name, int len, void *data, void *file) } #define CHECKED_WRITE_BUFF(name,buff) { \ - if (PicoStateProgressCB && name < CHUNK_DEFAULT_COUNT) { \ + if (PicoStateProgressCB && name < CHUNK_DEFAULT_COUNT && chunk_names[name]) { \ strncpy(sbuff + 9, chunk_names[name], sizeof(sbuff) - 9); \ PicoStateProgressCB(sbuff); \ } \