[hackers] [st] Avoid buffer overrun in kpress() and remove limit on shortcut strings. || Mark Edgar

From: <git_AT_suckless.org>
Date: Tue, 15 Oct 2013 17:44:04 +0200

commit 939e149544e4da958c333f3b6d00991d459c2e34
Author: Mark Edgar <medgar123_AT_gmail.com>
Date: Sat Oct 5 11:45:44 2013 +0200

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

diff --git a/st.c b/st.c
index 331509f..16bf68b 100644
--- a/st.c
+++ b/st.c
_AT_@ -264,7 +264,7 @@ typedef struct {
 typedef struct {
         KeySym k;
         uint mask;
- char s[ESC_BUF_SIZ];
+ char *s;
         /* three valued logic variables: 0 indifferent, 1 on, -1 off */
         signed char appkey; /* application keypad */
         signed char appcursor; /* application cursor */
_AT_@ -3585,26 +3585,27 @@ kpress(XEvent *ev) {
         /* 2. custom keys from config.h */
         if((customkey = kmap(ksym, e->state))) {
                 len = strlen(customkey);
- memcpy(buf, customkey, len);
- /* 3. composed string from input method */
- } else {
- if(len == 0)
- return;
+ ttywrite(customkey, len);
+ if(IS_SET(MODE_ECHO))
+ techo(customkey, len);
+ return;
+ }
 
- if(len == 1 && e->state & Mod1Mask) {
- if(IS_SET(MODE_8BIT)) {
- if(*buf < 0177) {
- c = *buf | 0x80;
- len = utf8encode(&c, buf);
- }
- } else {
- buf[1] = buf[0];
- buf[0] = '';
- len = 2;
+ /* 3. composed string from input method */
+ if(len == 0)
+ return;
+ if(len == 1 && e->state & Mod1Mask) {
+ if(IS_SET(MODE_8BIT)) {
+ if(*buf < 0177) {
+ c = *buf | 0x80;
+ len = utf8encode(&c, buf);
                         }
+ } else {
+ buf[1] = buf[0];
+ buf[0] = '';
+ len = 2;
                 }
         }
-
         ttywrite(buf, len);
         if(IS_SET(MODE_ECHO))
                 techo(buf, len);
Received on Tue Oct 15 2013 - 17:44:04 CEST

This archive was generated by hypermail 2.3.0 : Tue Oct 15 2013 - 17:48:31 CEST