From 144e0b5068aa25b7fce822a94101586f374aa236 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Sun, 23 Aug 2015 20:57:49 +0200 Subject: [PATCH] add option to disable terminology escape codes that could be considered security issues by some They are enabled by default. --- src/bin/config.c | 13 +++- src/bin/config.h | 1 + src/bin/options_behavior.c | 2 + src/bin/termio.c | 126 ++++++++++++++++++++++++++----------- src/bin/termptyesc.c | 17 +++-- 5 files changed, 116 insertions(+), 43 deletions(-) diff --git a/src/bin/config.c b/src/bin/config.c index ee0588a6..69f5abc9 100644 --- a/src/bin/config.c +++ b/src/bin/config.c @@ -7,7 +7,7 @@ #include "col.h" #include "utils.h" -#define CONF_VER 5 +#define CONF_VER 6 #define LIM(v, min, max) {if (v >= max) v = max; else if (v <= min) v = min;} @@ -163,6 +163,8 @@ config_init(void) (edd_base, Config, "notabs", notabs, EET_T_UCHAR); EET_DATA_DESCRIPTOR_ADD_BASIC (edd_base, Config, "mv_always_show", mv_always_show, EET_T_UCHAR); + EET_DATA_DESCRIPTOR_ADD_BASIC + (edd_base, Config, "ty_escapes", ty_escapes, EET_T_UCHAR); } void @@ -261,6 +263,8 @@ config_sync(const Config *config_src, Config *config) /* TODO: config->keys */ config->gravatar = config_src->gravatar; config->notabs = config_src->notabs; + config->mv_always_show = config_src->mv_always_show; + config->ty_escapes = config_src->ty_escapes; } static void @@ -472,7 +476,10 @@ config_load(const char *key) case 4: config->version = 5; /*pass through*/ - case CONF_VER: /* 5 */ + case 5: + config->ty_escapes = EINA_TRUE; + /*pass through*/ + case CONF_VER: /* 6 */ config->version = CONF_VER; break; default: @@ -536,6 +543,7 @@ config_load(const char *key) config->gravatar = EINA_TRUE; config->notabs = EINA_FALSE; config->mv_always_show = EINA_FALSE; + config->ty_escapes = EINA_TRUE; for (j = 0; j < 4; j++) { for (i = 0; i < 12; i++) @@ -628,6 +636,7 @@ config_fork(Config *config) CPY(gravatar); CPY(notabs); CPY(mv_always_show); + CPY(ty_escapes); EINA_LIST_FOREACH(config->keys, l, key) { diff --git a/src/bin/config.h b/src/bin/config.h index c7d3a102..79236695 100644 --- a/src/bin/config.h +++ b/src/bin/config.h @@ -75,6 +75,7 @@ struct _Config Eina_Bool gravatar; Eina_Bool notabs; Eina_Bool mv_always_show; + Eina_Bool ty_escapes; Config_Color colors[(4 * 12)]; Eina_List *keys; diff --git a/src/bin/options_behavior.c b/src/bin/options_behavior.c index 95bf6344..d889a467 100644 --- a/src/bin/options_behavior.c +++ b/src/bin/options_behavior.c @@ -42,6 +42,7 @@ CB(mouse_over_focus, 0); CB(gravatar, 0); CB(notabs, 1); CB(mv_always_show, 0); +CB(ty_escapes, 0); #undef CB @@ -191,6 +192,7 @@ options_behavior(Evas_Object *opbox, Evas_Object *term) CX(_("Gravatar integration"), gravatar, 0); CX(_("Show tabs"), notabs, 1); CX(_("Always show miniview"), mv_always_show, 0); + CX(_("Enable special Terminology escape codes"), ty_escapes, 0); #undef CX diff --git a/src/bin/termio.c b/src/bin/termio.c index b8794320..6eb1c8d7 100644 --- a/src/bin/termio.c +++ b/src/bin/termio.c @@ -5463,16 +5463,72 @@ _smart_pty_command(void *data) { Evas_Object *obj = data; Termio *sd = evas_object_smart_data_get(obj); + Config *config; + Termpty *ty; EINA_SAFETY_ON_NULL_RETURN(sd); - if (!sd->pty->cur_cmd) return; - if (sd->pty->cur_cmd[0] == 'i') + + config = sd->config; + ty = sd->pty; + if (!ty->cur_cmd) + return; + if (ty->cur_cmd[0] == 'q') { - if ((sd->pty->cur_cmd[1] == 's') || - (sd->pty->cur_cmd[1] == 'c') || - (sd->pty->cur_cmd[1] == 'f') || - (sd->pty->cur_cmd[1] == 't') || - (sd->pty->cur_cmd[1] == 'j')) + if (ty->cur_cmd[1] == 's') + { + char buf[256]; + + snprintf(buf, sizeof(buf), "%i;%i;%i;%i\n", + sd->grid.w, sd->grid.h, sd->font.chw, sd->font.chh); + termpty_write(ty, buf, strlen(buf)); + return; + } + else if (ty->cur_cmd[1] == 'j') + { + const char *chid = &(ty->cur_cmd[3]); + + if (ty->cur_cmd[2]) + { + if (ty->cur_cmd[2] == '+') + { + sd->cur_chids = eina_list_append + (sd->cur_chids, eina_stringshare_add(chid)); + } + else if (ty->cur_cmd[2] == '-') + { + Eina_List *l; + char *chid2; + + EINA_LIST_FOREACH(sd->cur_chids, l, chid2) + { + if (!(!strcmp(chid, chid2))) + { + sd->cur_chids = + eina_list_remove_list(sd->cur_chids, l); + eina_stringshare_del(chid2); + break; + } + } + } + } + else + { + EINA_LIST_FREE(sd->cur_chids, chid) + eina_stringshare_del(chid); + } + return; + } + return; + } + if (!config->ty_escapes) + return; + if (ty->cur_cmd[0] == 'i') + { + if ((ty->cur_cmd[1] == 's') || + (ty->cur_cmd[1] == 'c') || + (ty->cur_cmd[1] == 'f') || + (ty->cur_cmd[1] == 't') || + (ty->cur_cmd[1] == 'j')) { const char *p, *p0, *p1, *path = NULL; char *pp; @@ -5491,12 +5547,12 @@ _smart_pty_command(void *data) // \nCMD\nP1[\nP2][\nP3][[\nCMD2\nP21[\nP22]]... // CMD is the command, P1, P2, P3 etc. are parameters (P2 and // on are optional depending on CMD) - repch = sd->pty->cur_cmd[2]; + repch = ty->cur_cmd[2]; if (repch) { char *link = NULL; - for (p0 = p = &(sd->pty->cur_cmd[3]); *p; p++) + for (p0 = p = &(ty->cur_cmd[3]); *p; p++) { if (*p == ';') { @@ -5514,7 +5570,7 @@ _smart_pty_command(void *data) break; } } - if (sd->pty->cur_cmd[1] == 'j') + if (ty->cur_cmd[1] == 'j') { // parse from p until end of string - one newline // per list item in strs @@ -5572,7 +5628,7 @@ _smart_pty_command(void *data) file = eina_list_nth(strs, 0); group = eina_list_nth(strs, 1); l = eina_list_nth_list(strs, 2); - blk = termpty_block_new(sd->pty, ww, hh, file, group); + blk = termpty_block_new(ty, ww, hh, file, group); for (;l; l = l->next) { pp = l->data; @@ -5582,20 +5638,20 @@ _smart_pty_command(void *data) } } else - blk = termpty_block_new(sd->pty, ww, hh, path, link); + blk = termpty_block_new(ty, ww, hh, path, link); if (blk) { - if (sd->pty->cur_cmd[1] == 's') + if (ty->cur_cmd[1] == 's') blk->scale_stretch = EINA_TRUE; - else if (sd->pty->cur_cmd[1] == 'c') + else if (ty->cur_cmd[1] == 'c') blk->scale_center = EINA_TRUE; - else if (sd->pty->cur_cmd[1] == 'f') + else if (ty->cur_cmd[1] == 'f') blk->scale_fill = EINA_TRUE; - else if (sd->pty->cur_cmd[1] == 't') + else if (ty->cur_cmd[1] == 't') blk->thumb = EINA_TRUE; - else if (sd->pty->cur_cmd[1] == 'j') + else if (ty->cur_cmd[1] == 'j') blk->edje = EINA_TRUE; - termpty_block_insert(sd->pty, repch, blk); + termpty_block_insert(ty, repch, blk); } } free(link); @@ -5603,14 +5659,14 @@ _smart_pty_command(void *data) } return; } - else if (sd->pty->cur_cmd[1] == 'C') + else if (ty->cur_cmd[1] == 'C') { Termblock *blk = NULL; const char *p, *p0, *p1; char *pp; Eina_List *strs = NULL; - p = &(sd->pty->cur_cmd[2]); + p = &(ty->cur_cmd[2]); // parse from p until end of string - one newline // per list item in strs p0 = p1 = p; @@ -5642,46 +5698,46 @@ _smart_pty_command(void *data) if (strs) { char *chid = strs->data; - blk = termpty_block_chid_get(sd->pty, chid); + blk = termpty_block_chid_get(ty, chid); if (blk) { - _block_edje_cmds(sd->pty, blk, strs->next, EINA_FALSE); + _block_edje_cmds(ty, blk, strs->next, EINA_FALSE); } } EINA_LIST_FREE(strs, pp) free(pp); } - else if (sd->pty->cur_cmd[1] == 'b') + else if (ty->cur_cmd[1] == 'b') { - sd->pty->block.on = EINA_TRUE; + ty->block.on = EINA_TRUE; } - else if (sd->pty->cur_cmd[1] == 'e') + else if (ty->cur_cmd[1] == 'e') { - sd->pty->block.on = EINA_FALSE; + ty->block.on = EINA_FALSE; } } - else if (sd->pty->cur_cmd[0] == 'q') + else if (ty->cur_cmd[0] == 'q') { - if (sd->pty->cur_cmd[1] == 's') + if (ty->cur_cmd[1] == 's') { char buf[256]; snprintf(buf, sizeof(buf), "%i;%i;%i;%i\n", sd->grid.w, sd->grid.h, sd->font.chw, sd->font.chh); - termpty_write(sd->pty, buf, strlen(buf)); + termpty_write(ty, buf, strlen(buf)); return; } - else if (sd->pty->cur_cmd[1] == 'j') + else if (ty->cur_cmd[1] == 'j') { - const char *chid = &(sd->pty->cur_cmd[3]); + const char *chid = &(ty->cur_cmd[3]); - if (sd->pty->cur_cmd[2]) + if (ty->cur_cmd[2]) { - if (sd->pty->cur_cmd[2] == '+') + if (ty->cur_cmd[2] == '+') { sd->cur_chids = eina_list_append (sd->cur_chids, eina_stringshare_add(chid)); } - else if (sd->pty->cur_cmd[2] == '-') + else if (ty->cur_cmd[2] == '-') { Eina_List *l; char *chid2; @@ -5706,7 +5762,7 @@ _smart_pty_command(void *data) return; } } - evas_object_smart_callback_call(obj, "command", (void *)sd->pty->cur_cmd); + evas_object_smart_callback_call(obj, "command", (void *)ty->cur_cmd); } #if !((ELM_VERSION_MAJOR == 1) && (ELM_VERSION_MINOR < 8)) diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c index bd525c3b..301574ab 100644 --- a/src/bin/termptyesc.c +++ b/src/bin/termptyesc.c @@ -1442,8 +1442,11 @@ _handle_esc_terminology(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode * { Eina_Unicode *cc; Eina_Unicode *buf, bufsmall[1024], *b; - char *s; - int blen = 0, slen = 0; + char *cmd; + int blen = 0; + Config *config; + + config = termio_config_get(ty->obj); cc = (Eina_Unicode *)c; while ((cc < ce) && (*cc != 0x0)) @@ -1469,15 +1472,17 @@ _handle_esc_terminology(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode * return 0; } *b = 0; + // commands are stored in the buffer, 0 bytes not allowed (end marker) - s = eina_unicode_unicode_to_utf8(buf, &slen); - ty->cur_cmd = s; - if (!_termpty_ext_handle(ty, s, buf)) + cmd = eina_unicode_unicode_to_utf8(buf, NULL); + ty->cur_cmd = cmd; + if ((!config->ty_escapes) || (!_termpty_ext_handle(ty, cmd, buf))) { if (ty->cb.command.func) ty->cb.command.func(ty->cb.command.data); } ty->cur_cmd = NULL; - free(s); + free(cmd); + if (buf != bufsmall) free(buf); return cc - c; }