diff options
author | Jack Palevich <jackpal@google.com> | 2012-09-22 18:25:26 -0700 |
---|---|---|
committer | Jack Palevich <jackpal@google.com> | 2012-09-22 18:25:26 -0700 |
commit | a4d3f1997551a65eb65cdf68508e4d4b7950bc57 (patch) | |
tree | 9444ebf2b744618099f94564aeaef4a76a41ef04 | |
parent | f36613fffb746a2e7d64a711c692d205c7646369 (diff) | |
download | AndroidTerm-a4d3f1997551a65eb65cdf68508e4d4b7950bc57.tar.gz |
Validate foreground and background colors are in range.
Fixes issue 156
-rw-r--r-- | libraries/emulatorview/src/jackpal/androidterm/emulatorview/TerminalEmulator.java | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/libraries/emulatorview/src/jackpal/androidterm/emulatorview/TerminalEmulator.java b/libraries/emulatorview/src/jackpal/androidterm/emulatorview/TerminalEmulator.java index 30f7e72..4e755ca 100644 --- a/libraries/emulatorview/src/jackpal/androidterm/emulatorview/TerminalEmulator.java +++ b/libraries/emulatorview/src/jackpal/androidterm/emulatorview/TerminalEmulator.java @@ -1240,7 +1240,10 @@ class TerminalEmulator { } else if (code >= 30 && code <= 37) { // foreground color mForeColor = code - 30; } else if (code == 38 && i+2 <= mArgIndex && mArgs[i+1] == 5) { // foreground 256 color - mForeColor = mArgs[i+2]; + int color = mArgs[i+2]; + if (checkColor(color)) { + mForeColor = color; + } i += 2; } else if (code == 39) { // set default text color mForeColor = mDefaultForeColor; @@ -1248,6 +1251,10 @@ class TerminalEmulator { mBackColor = code - 40; } else if (code == 48 && i+2 <= mArgIndex && mArgs[i+1] == 5) { // background 256 color mBackColor = mArgs[i+2]; + int color = mArgs[i+2]; + if (checkColor(color)) { + mForeColor = color; + } i += 2; } else if (code == 49) { // set default background color mBackColor = mDefaultBackColor; @@ -1263,6 +1270,21 @@ class TerminalEmulator { } } + private boolean checkColor(int color) { + boolean result = isValidColor(color); + if (!result) { + if (EmulatorDebug.LOG_UNKNOWN_ESCAPE_SEQUENCES) { + Log.w(EmulatorDebug.LOG_TAG, + String.format("Invalid color %d", color)); + } + } + return result; + } + + private boolean isValidColor(int color) { + return color >= 0 && color < TextStyle.ciColorLength; + } + private void doEscRightSquareBracket(byte b) { switch (b) { case 0x7: |