]> git.pond.sub.org Git - empserver/commitdiff
(termio): Fix crash bug: when input line starts with '?', `s' was used
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 18 Dec 2004 08:53:23 +0000 (08:53 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 18 Dec 2004 08:53:23 +0000 (08:53 +0000)
uninitialized.

(buf, exec, termio): Make buf[] and exec[] local to termio().

src/client/tags.c
src/client/tags.h
src/client/termio.c

index 0903fe228935da0a2391d6ef7e3f5a5b79aec9bf..3531ca9eb6d4b188e92c94d10bb1b645f935a57d 100644 (file)
 #endif
 
 struct tagstruct *taglist;
-s_char buf[4096];
-s_char exec[8];
-static unsigned short tagnum;
 
 void
 io_init(void)
 {
     taglist = NULL;
-    buf[0] = 0;
-    tagnum = 0;
-    sprintf(exec, "execute");
 }
 
 s_char *
index a50c9772ca7bb650c2149dca4cd93e5252d6a02e..b437c9f003e04383738afa51504c27d8f16ab122 100644 (file)
@@ -40,8 +40,6 @@ struct tagstruct {
 };
 
 extern struct tagstruct *taglist;
-extern s_char buf[4096];
-extern s_char exec[8];
 
 void io_init(void);
 s_char *gettag(s_char *p);
index 376c4a935f4f8a759ce85e40e4070c78f6583e79..31b6c694d98b22fdb2d26c3cdd553af87cd84c96 100644 (file)
 int
 termio(int fd, int sock, FILE *auxfi)
 {
+    static char exec[] = "execute";
+    static char buf[4096];
     s_char out[4096];
     int i, n;
     s_char *ptr;
     s_char *p, *q, *r, *s, *t;
     int nbytes;
-    int numarg, prespace, exec_com, inarg, quoted, tagging;
+    int prespace, exec_com, inarg, quoted, tagging;
     struct tagstruct *tag;
 #ifdef _WIN32
     char c;
@@ -123,11 +125,11 @@ termio(int fd, int sock, FILE *auxfi)
     p = buf;
     q = out;
     r = out;
-    numarg = 0;
     tagging = 0;
     inarg = 0;
     prespace = 1;
     quoted = 0;
+    exec_com = 0;
     while (p < buf + n && q < out + 4000) {
        if (*p == '\n') {
            if (tagging) {
@@ -141,11 +143,11 @@ termio(int fd, int sock, FILE *auxfi)
                *t = 0;
            }
            *q++ = *p++;
-           numarg = 0;
            tagging = 0;
            inarg = 0;
            prespace = 1;
            quoted = 0;
+           exec_com = 0;
            ptr = p;
            r = q;
        } else if (tagging) {
@@ -153,7 +155,7 @@ termio(int fd, int sock, FILE *auxfi)
        } else if (!quoted && isspace(*p)) {
            *q++ = *p++;
            prespace = 1;
-           if (numarg == 1 && exec_com && s > exec + 2) {
+           if (exec_com && s > exec + 2) {
                tagging = 1;
                s = p;
            }
@@ -175,10 +177,9 @@ termio(int fd, int sock, FILE *auxfi)
                if (!inarg && *p != '?') {
                    s = exec;
                    exec_com = 1;
-                   numarg++;
+                   inarg = 1;
                }
-               inarg = 1;
-               if (*s && *s++ != *p)
+               if (exec_com && *s && *s++ != *p)
                    exec_com = 0;
            }
            *q++ = *p++;