add option to disable terminology escape codes that could be considered

security issues by some

They are enabled by default.
This commit is contained in:
Boris Faure 2015-08-23 20:57:49 +02:00
parent 5c9d98cf22
commit 144e0b5068
5 changed files with 116 additions and 43 deletions

View File

@ -7,7 +7,7 @@
#include "col.h" #include "col.h"
#include "utils.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;} #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); (edd_base, Config, "notabs", notabs, EET_T_UCHAR);
EET_DATA_DESCRIPTOR_ADD_BASIC EET_DATA_DESCRIPTOR_ADD_BASIC
(edd_base, Config, "mv_always_show", mv_always_show, EET_T_UCHAR); (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 void
@ -261,6 +263,8 @@ config_sync(const Config *config_src, Config *config)
/* TODO: config->keys */ /* TODO: config->keys */
config->gravatar = config_src->gravatar; config->gravatar = config_src->gravatar;
config->notabs = config_src->notabs; config->notabs = config_src->notabs;
config->mv_always_show = config_src->mv_always_show;
config->ty_escapes = config_src->ty_escapes;
} }
static void static void
@ -472,7 +476,10 @@ config_load(const char *key)
case 4: case 4:
config->version = 5; config->version = 5;
/*pass through*/ /*pass through*/
case CONF_VER: /* 5 */ case 5:
config->ty_escapes = EINA_TRUE;
/*pass through*/
case CONF_VER: /* 6 */
config->version = CONF_VER; config->version = CONF_VER;
break; break;
default: default:
@ -536,6 +543,7 @@ config_load(const char *key)
config->gravatar = EINA_TRUE; config->gravatar = EINA_TRUE;
config->notabs = EINA_FALSE; config->notabs = EINA_FALSE;
config->mv_always_show = EINA_FALSE; config->mv_always_show = EINA_FALSE;
config->ty_escapes = EINA_TRUE;
for (j = 0; j < 4; j++) for (j = 0; j < 4; j++)
{ {
for (i = 0; i < 12; i++) for (i = 0; i < 12; i++)
@ -628,6 +636,7 @@ config_fork(Config *config)
CPY(gravatar); CPY(gravatar);
CPY(notabs); CPY(notabs);
CPY(mv_always_show); CPY(mv_always_show);
CPY(ty_escapes);
EINA_LIST_FOREACH(config->keys, l, key) EINA_LIST_FOREACH(config->keys, l, key)
{ {

View File

@ -75,6 +75,7 @@ struct _Config
Eina_Bool gravatar; Eina_Bool gravatar;
Eina_Bool notabs; Eina_Bool notabs;
Eina_Bool mv_always_show; Eina_Bool mv_always_show;
Eina_Bool ty_escapes;
Config_Color colors[(4 * 12)]; Config_Color colors[(4 * 12)];
Eina_List *keys; Eina_List *keys;

View File

@ -42,6 +42,7 @@ CB(mouse_over_focus, 0);
CB(gravatar, 0); CB(gravatar, 0);
CB(notabs, 1); CB(notabs, 1);
CB(mv_always_show, 0); CB(mv_always_show, 0);
CB(ty_escapes, 0);
#undef CB #undef CB
@ -191,6 +192,7 @@ options_behavior(Evas_Object *opbox, Evas_Object *term)
CX(_("Gravatar integration"), gravatar, 0); CX(_("Gravatar integration"), gravatar, 0);
CX(_("Show tabs"), notabs, 1); CX(_("Show tabs"), notabs, 1);
CX(_("Always show miniview"), mv_always_show, 0); CX(_("Always show miniview"), mv_always_show, 0);
CX(_("Enable special Terminology escape codes"), ty_escapes, 0);
#undef CX #undef CX

View File

@ -5463,16 +5463,72 @@ _smart_pty_command(void *data)
{ {
Evas_Object *obj = data; Evas_Object *obj = data;
Termio *sd = evas_object_smart_data_get(obj); Termio *sd = evas_object_smart_data_get(obj);
Config *config;
Termpty *ty;
EINA_SAFETY_ON_NULL_RETURN(sd); 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') || if (ty->cur_cmd[1] == 's')
(sd->pty->cur_cmd[1] == 'c') || {
(sd->pty->cur_cmd[1] == 'f') || char buf[256];
(sd->pty->cur_cmd[1] == 't') ||
(sd->pty->cur_cmd[1] == 'j')) 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; const char *p, *p0, *p1, *path = NULL;
char *pp; char *pp;
@ -5491,12 +5547,12 @@ _smart_pty_command(void *data)
// \nCMD\nP1[\nP2][\nP3][[\nCMD2\nP21[\nP22]]... // \nCMD\nP1[\nP2][\nP3][[\nCMD2\nP21[\nP22]]...
// CMD is the command, P1, P2, P3 etc. are parameters (P2 and // CMD is the command, P1, P2, P3 etc. are parameters (P2 and
// on are optional depending on CMD) // on are optional depending on CMD)
repch = sd->pty->cur_cmd[2]; repch = ty->cur_cmd[2];
if (repch) if (repch)
{ {
char *link = NULL; char *link = NULL;
for (p0 = p = &(sd->pty->cur_cmd[3]); *p; p++) for (p0 = p = &(ty->cur_cmd[3]); *p; p++)
{ {
if (*p == ';') if (*p == ';')
{ {
@ -5514,7 +5570,7 @@ _smart_pty_command(void *data)
break; break;
} }
} }
if (sd->pty->cur_cmd[1] == 'j') if (ty->cur_cmd[1] == 'j')
{ {
// parse from p until end of string - one newline // parse from p until end of string - one newline
// per list item in strs // per list item in strs
@ -5572,7 +5628,7 @@ _smart_pty_command(void *data)
file = eina_list_nth(strs, 0); file = eina_list_nth(strs, 0);
group = eina_list_nth(strs, 1); group = eina_list_nth(strs, 1);
l = eina_list_nth_list(strs, 2); 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) for (;l; l = l->next)
{ {
pp = l->data; pp = l->data;
@ -5582,20 +5638,20 @@ _smart_pty_command(void *data)
} }
} }
else else
blk = termpty_block_new(sd->pty, ww, hh, path, link); blk = termpty_block_new(ty, ww, hh, path, link);
if (blk) if (blk)
{ {
if (sd->pty->cur_cmd[1] == 's') if (ty->cur_cmd[1] == 's')
blk->scale_stretch = EINA_TRUE; 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; 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; blk->scale_fill = EINA_TRUE;
else if (sd->pty->cur_cmd[1] == 't') else if (ty->cur_cmd[1] == 't')
blk->thumb = EINA_TRUE; blk->thumb = EINA_TRUE;
else if (sd->pty->cur_cmd[1] == 'j') else if (ty->cur_cmd[1] == 'j')
blk->edje = EINA_TRUE; blk->edje = EINA_TRUE;
termpty_block_insert(sd->pty, repch, blk); termpty_block_insert(ty, repch, blk);
} }
} }
free(link); free(link);
@ -5603,14 +5659,14 @@ _smart_pty_command(void *data)
} }
return; return;
} }
else if (sd->pty->cur_cmd[1] == 'C') else if (ty->cur_cmd[1] == 'C')
{ {
Termblock *blk = NULL; Termblock *blk = NULL;
const char *p, *p0, *p1; const char *p, *p0, *p1;
char *pp; char *pp;
Eina_List *strs = NULL; Eina_List *strs = NULL;
p = &(sd->pty->cur_cmd[2]); p = &(ty->cur_cmd[2]);
// parse from p until end of string - one newline // parse from p until end of string - one newline
// per list item in strs // per list item in strs
p0 = p1 = p; p0 = p1 = p;
@ -5642,46 +5698,46 @@ _smart_pty_command(void *data)
if (strs) if (strs)
{ {
char *chid = strs->data; char *chid = strs->data;
blk = termpty_block_chid_get(sd->pty, chid); blk = termpty_block_chid_get(ty, chid);
if (blk) 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); 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]; char buf[256];
snprintf(buf, sizeof(buf), "%i;%i;%i;%i\n", snprintf(buf, sizeof(buf), "%i;%i;%i;%i\n",
sd->grid.w, sd->grid.h, sd->font.chw, sd->font.chh); 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; 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_list_append
(sd->cur_chids, eina_stringshare_add(chid)); (sd->cur_chids, eina_stringshare_add(chid));
} }
else if (sd->pty->cur_cmd[2] == '-') else if (ty->cur_cmd[2] == '-')
{ {
Eina_List *l; Eina_List *l;
char *chid2; char *chid2;
@ -5706,7 +5762,7 @@ _smart_pty_command(void *data)
return; 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)) #if !((ELM_VERSION_MAJOR == 1) && (ELM_VERSION_MINOR < 8))

View File

@ -1442,8 +1442,11 @@ _handle_esc_terminology(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *
{ {
Eina_Unicode *cc; Eina_Unicode *cc;
Eina_Unicode *buf, bufsmall[1024], *b; Eina_Unicode *buf, bufsmall[1024], *b;
char *s; char *cmd;
int blen = 0, slen = 0; int blen = 0;
Config *config;
config = termio_config_get(ty->obj);
cc = (Eina_Unicode *)c; cc = (Eina_Unicode *)c;
while ((cc < ce) && (*cc != 0x0)) while ((cc < ce) && (*cc != 0x0))
@ -1469,15 +1472,17 @@ _handle_esc_terminology(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *
return 0; return 0;
} }
*b = 0; *b = 0;
// commands are stored in the buffer, 0 bytes not allowed (end marker) // commands are stored in the buffer, 0 bytes not allowed (end marker)
s = eina_unicode_unicode_to_utf8(buf, &slen); cmd = eina_unicode_unicode_to_utf8(buf, NULL);
ty->cur_cmd = s; ty->cur_cmd = cmd;
if (!_termpty_ext_handle(ty, s, buf)) if ((!config->ty_escapes) || (!_termpty_ext_handle(ty, cmd, buf)))
{ {
if (ty->cb.command.func) ty->cb.command.func(ty->cb.command.data); if (ty->cb.command.func) ty->cb.command.func(ty->cb.command.data);
} }
ty->cur_cmd = NULL; ty->cur_cmd = NULL;
free(s); free(cmd);
if (buf != bufsmall) free(buf); if (buf != bufsmall) free(buf);
return cc - c; return cc - c;
} }