(svn r17611) -Fix: buffers used for verifying company and president name length were too short, possibly causing false positives

This commit is contained in:
smatz
2009-09-22 12:42:56 +00:00
parent 3a7da30922
commit 665864e5b0
3 changed files with 13 additions and 6 deletions

View File

@@ -260,7 +260,9 @@ static void GenerateCompanyName(Company *c)
StringID str;
Company *cc;
uint32 strp;
char buffer[100];
/* Reserve space for extra unicode character. We need to do this to be able
* to detect too long company name. */
char buffer[MAX_LENGTH_COMPANY_NAME_BYTES + MAX_CHAR_LENGTH];
if (c->name_1 != STR_SV_UNNAMED) return;
@@ -392,7 +394,9 @@ restart:;
c->president_name_2 = Random();
c->president_name_1 = SPECSTR_PRESIDENT_NAME;
char buffer[MAX_LENGTH_PRESIDENT_NAME_BYTES + 1];
/* Reserve space for extra unicode character. We need to do this to be able
* to detect too long president name. */
char buffer[MAX_LENGTH_PRESIDENT_NAME_BYTES + MAX_CHAR_LENGTH];
SetDParam(0, c->index);
GetString(buffer, STR_PRESIDENT_NAME, lastof(buffer));
if (strlen(buffer) >= MAX_LENGTH_PRESIDENT_NAME_BYTES) continue;
@@ -400,7 +404,8 @@ restart:;
Company *cc;
FOR_ALL_COMPANIES(cc) {
if (c != cc) {
char buffer2[MAX_LENGTH_PRESIDENT_NAME_BYTES + 2];
/* Reserve extra space so even overlength president names can be compared. */
char buffer2[MAX_LENGTH_PRESIDENT_NAME_BYTES + MAX_CHAR_LENGTH];
SetDParam(0, cc->index);
GetString(buffer2, STR_PRESIDENT_NAME, lastof(buffer2));
if (strcmp(buffer2, buffer) == 0) goto restart;