• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


コミットメタ情報

リビジョンf1f39cca305f6f3d2d91b88736b7b2b520d59e2e (tree)
日時2009-05-30 10:03:15
作者Jack Palevich <jackpal@goog...>
コミッターJack Palevich

ログメッセージ

Make sure we don't overflow various internal compiler buffers.

We may replace some of these tables with dynamically growing data
structures, but in the meantime we will not trash memory.

変更サマリ

差分

--- a/libacc/acc.cpp
+++ b/libacc/acc.cpp
@@ -1083,7 +1083,7 @@ class Compiler : public ErrorSink {
10831083 int dch; // Macro state: Saves old value of ch during a macro playback.
10841084 char* last_id;
10851085 void* pSymbolBase;
1086- void* pGlobalBase;
1086+ char* pGlobalBase;
10871087 char* pVarsBase; // Value of variables
10881088
10891089 InputStream* file;
@@ -1154,6 +1154,9 @@ class Compiler : public ErrorSink {
11541154 static const char operatorLevel[];
11551155
11561156 void pdef(int t) {
1157+ if (dstk - sym_stk >= ALLOC_SIZE) {
1158+ error("Symbol table exhausted");
1159+ }
11571160 *dstk++ = t;
11581161 }
11591162
@@ -1219,6 +1222,9 @@ class Compiler : public ErrorSink {
12191222 tokc = strtol(last_id, 0, 0);
12201223 tok = TOK_NUM;
12211224 } else {
1225+ if (dstk - sym_stk + 1 > ALLOC_SIZE) {
1226+ error("symbol stack overflow");
1227+ }
12221228 * dstk = TAG_TOK; /* no need to mark end of string (we
12231229 suppose data is initialized to zero by calloc) */
12241230 tok = (intptr_t) (strstr(sym_stk, (last_id - 1))
@@ -1226,6 +1232,9 @@ class Compiler : public ErrorSink {
12261232 * dstk = 0; /* mark real end of ident for dlsym() */
12271233 tok = tok * 8 + TOK_IDENT;
12281234 if (tok > TOK_DEFINE) {
1235+ if (tok + 8 > ALLOC_SIZE) {
1236+ error("Variable Table overflow.");
1237+ }
12291238 tok = (intptr_t) (pVarsBase + tok);
12301239 /* printf("tok=%s %x\n", last_id, tok); */
12311240 /* define handling */
@@ -1350,11 +1359,12 @@ class Compiler : public ErrorSink {
13501359 pGen->li((int) glo);
13511360 while (ch != '\"') {
13521361 getq();
1353- *glo++ = ch;
1362+ *allocGlobalSpace(1) = ch;
13541363 inp();
13551364 }
13561365 *glo = 0;
1357- glo = (char*) (((intptr_t) glo + 4) & -4); /* align heap */
1366+ /* align heap */
1367+ allocGlobalSpace((char*) (((intptr_t) glo + 4) & -4) - glo);
13581368 inp();
13591369 next();
13601370 } else {
@@ -1584,8 +1594,7 @@ class Compiler : public ErrorSink {
15841594 loc = loc + 4;
15851595 *(int *) tok = -loc;
15861596 } else {
1587- *(int* *) tok = (int*) glo;
1588- glo = glo + 4;
1597+ *(int* *) tok = (int*) allocGlobalSpace(4);
15891598 }
15901599 next();
15911600 if (tok == ',')
@@ -1621,13 +1630,22 @@ class Compiler : public ErrorSink {
16211630 }
16221631 }
16231632
1633+ char* allocGlobalSpace(int bytes) {
1634+ if (glo - pGlobalBase + bytes > ALLOC_SIZE) {
1635+ error("Global space exhausted");
1636+ }
1637+ char* result = glo;
1638+ glo += bytes;
1639+ return result;
1640+ }
1641+
16241642 void cleanup() {
16251643 if (sym_stk != 0) {
16261644 free(sym_stk);
16271645 sym_stk = 0;
16281646 }
16291647 if (pGlobalBase != 0) {
1630- free((void*) pGlobalBase);
1648+ free(pGlobalBase);
16311649 pGlobalBase = 0;
16321650 }
16331651 if (pVarsBase != 0) {
@@ -1730,8 +1748,8 @@ public:
17301748 dstk = strcpy(sym_stk,
17311749 " int if else while break return for define main ")
17321750 + TOK_STR_SIZE;
1733- pGlobalBase = calloc(1, ALLOC_SIZE);
1734- glo = (char*) pGlobalBase;
1751+ pGlobalBase = (char*) calloc(1, ALLOC_SIZE);
1752+ glo = pGlobalBase;
17351753 pVarsBase = (char*) calloc(1, ALLOC_SIZE);
17361754 inp();
17371755 next();