Avoid buffer overrun in kpress() and remove limit on shortcut strings.

master
Mark Edgar 11 years ago committed by Roberto E. Vargas Caballero
parent 02ae3ce6fd
commit 939e149544

35
st.c

@ -264,7 +264,7 @@ typedef struct {
typedef struct { typedef struct {
KeySym k; KeySym k;
uint mask; uint mask;
char s[ESC_BUF_SIZ]; char *s;
/* three valued logic variables: 0 indifferent, 1 on, -1 off */ /* three valued logic variables: 0 indifferent, 1 on, -1 off */
signed char appkey; /* application keypad */ signed char appkey; /* application keypad */
signed char appcursor; /* application cursor */ signed char appcursor; /* application cursor */
@ -3585,26 +3585,27 @@ kpress(XEvent *ev) {
/* 2. custom keys from config.h */ /* 2. custom keys from config.h */
if((customkey = kmap(ksym, e->state))) { if((customkey = kmap(ksym, e->state))) {
len = strlen(customkey); len = strlen(customkey);
memcpy(buf, customkey, len); ttywrite(customkey, len);
/* 3. composed string from input method */ if(IS_SET(MODE_ECHO))
} else { techo(customkey, len);
if(len == 0) return;
return; }
if(len == 1 && e->state & Mod1Mask) { /* 3. composed string from input method */
if(IS_SET(MODE_8BIT)) { if(len == 0)
if(*buf < 0177) { return;
c = *buf | 0x80; if(len == 1 && e->state & Mod1Mask) {
len = utf8encode(&c, buf); if(IS_SET(MODE_8BIT)) {
} if(*buf < 0177) {
} else { c = *buf | 0x80;
buf[1] = buf[0]; len = utf8encode(&c, buf);
buf[0] = '\033';
len = 2;
} }
} else {
buf[1] = buf[0];
buf[0] = '\033';
len = 2;
} }
} }
ttywrite(buf, len); ttywrite(buf, len);
if(IS_SET(MODE_ECHO)) if(IS_SET(MODE_ECHO))
techo(buf, len); techo(buf, len);

Loading…
Cancel
Save