From 8036a0225b060b4911b4e66bf3ac4288b089e48f Mon Sep 17 00:00:00 2001 From: avolkov Date: Mon, 23 Jan 2006 21:55:26 +0000 Subject: [PATCH] Fixed a buffer overflow in comm summary with non-English translations git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2228 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/src/sc2code/comm.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sc2/src/sc2code/comm.c b/sc2/src/sc2code/comm.c index 1767413fe..6ae98c868 100644 --- a/sc2/src/sc2code/comm.c +++ b/sc2/src/sc2code/comm.c @@ -1524,9 +1524,8 @@ DoCommunication (PENCOUNTER_STATE pES) TEXT t; #define DELTA_Y_SUMMARY 8 #define SUMMARY_CHARS (SIS_SCREEN_WIDTH - 34) / 4 -#define MAX_SUMMARY_CHARS 52 #define MAX_COLS ((SIS_SCREEN_HEIGHT - SLIDER_Y - SLIDER_HEIGHT - DELTA_Y_SUMMARY) / 8) - 1 - UNICODE buffer[MAX_SUMMARY_CHARS]; + UNICODE buffer[320]; // SUMMARY_CHARS * 6 UNICODE *temp; int i; int col = 0; @@ -1563,7 +1562,6 @@ DoCommunication (PENCOUNTER_STATE pES) temp = curr->text; if (temp == NULL) continue; - // fprintf (stderr, "%s\n", temp); while (utf8StringCount (temp) > (unsigned int) SUMMARY_CHARS && !(GLOBAL (CurrentActivity) & CHECK_ABORT)) { @@ -1579,6 +1577,13 @@ DoCommunication (PENCOUNTER_STATE pES) break; } } + if ((unsigned)space_index >= sizeof (buffer)) + { + fprintf (stderr, "DoCommunication() BUG: buffer[%u] " + "too small to fit %d bytes\n", + sizeof (buffer), space_index); + abort (); + } strncpy (buffer, temp, space_index); buffer[space_index] = '\0'; temp += space_index + 1;