comparison src/com/five_ten_sg/connectbot/service/TerminalMonitor.java @ 250:2bf2724d8610

add range checking on get/set fields
author Carl Byington <carl@five-ten-sg.com>
date Mon, 14 Jul 2014 12:21:43 -0700
parents ea49747c5447
children 587570134645
comparison
equal deleted inserted replaced
249:dc6e53600ae2 250:2bf2724d8610
415 screenChanged(l, l, c, c); 415 screenChanged(l, l, c, c);
416 } 416 }
417 417
418 public synchronized void setField(int l, int c, char[] data, int offset) { 418 public synchronized void setField(int l, int c, char[] data, int offset) {
419 Log.i(TAG, "setField()"); 419 Log.i(TAG, "setField()");
420 char[] da = new char[data.length - offset]; 420 int len = data.length - offset;
421 System.arraycopy(data, offset, da, 0, data.length-offset); 421 char[] da = new char[len];
422 if (l > 60000) l = -1; 422 System.arraycopy(data, offset, da, 0, len);
423 if (c > 60000) c = -1; 423 if ((l > 60000) || (c > 60000)) {
424 l = -1;
425 c = -1;
426 }
427 else {
428 // ignore setfield outside screen boundaries
429 if ((l >= buffer.height) || (c+len >= buffer.width)) return;
430 }
424 buffer.setField(l, c, da); 431 buffer.setField(l, c, da);
425 } 432 }
426 433
427 public synchronized void showUrl(char [] data, int offset) { 434 public synchronized void showUrl(char [] data, int offset) {
428 Log.i(TAG, "setField()"); 435 Log.i(TAG, "setField()");
437 Log.i(TAG, "getField()"); 444 Log.i(TAG, "getField()");
438 char[] arg2 = new char[4 + len]; 445 char[] arg2 = new char[4 + len];
439 arg2[2] = (char)(l & 0x0000ffff); 446 arg2[2] = (char)(l & 0x0000ffff);
440 arg2[3] = (char)(c & 0x0000ffff); 447 arg2[3] = (char)(c & 0x0000ffff);
441 int base = 4; 448 int base = 4;
442 System.arraycopy(buffer.charArray[buffer.screenBase + l], c, arg2, base, len); 449 if ((l >= buffer.height) || (c+len >= buffer.width)) {
450 Arrays.fill(arg2, base, len-1, ' ');
451 }
452 else {
453 System.arraycopy(buffer.charArray[buffer.screenBase + l], c, arg2, base, len);
454 }
443 monitorWrite(MONITOR_CMD_FIELDVALUE, arg2); 455 monitorWrite(MONITOR_CMD_FIELDVALUE, arg2);
444 } 456 }
445 457
446 public synchronized void screenWatch(int l, int c, int len) { 458 public synchronized void screenWatch(int l, int c, int len) {
447 Log.i(TAG, "screenWatch()"); 459 Log.i(TAG, "screenWatch()");