]> git.pond.sub.org Git - empserver/commitdiff
client: Simplify rogue redirection and execute protection further
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 18 Jun 2017 16:57:28 +0000 (18:57 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 6 Aug 2017 09:22:29 +0000 (11:22 +0200)
recv_input() passes full lines to save_input().  Pass characters
instead.  Simpler, and doesn't truncate long lines.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
src/client/play.c
src/client/secure.c
src/client/secure.h

index 47e028a8784ee1d9263ed946b31d6915a7461cec..697fed653649b09b215a11a7b46a71df76cf37c0 100644 (file)
@@ -404,21 +404,13 @@ recv_output(int sock)
 static int
 recv_input(int fd, struct ring *inbuf)
 {
-    static struct lbuf cmdbuf;
     int n, i, ch;
-    char *line;
     int res = 1;
 
     n = ring_from_file(inbuf, fd);
     if (n < 0)
        return -1;
     if (n == 0) {
-       /* EOF on input */
-       if (lbuf_len(&cmdbuf)) {
-           /* incomplete line */
-           ring_putc(inbuf, '\n');
-           n++;
-       }
        /*
         * Can't put EOF cookie into INBUF here, it may not fit.
         * Leave it to caller.
@@ -430,11 +422,8 @@ recv_input(int fd, struct ring *inbuf)
     for (i = -n; i < 0; i++) {
        ch = ring_peek(inbuf, i);
        assert(ch != EOF);
-       if (ch != '\r' && lbuf_putc(&cmdbuf, ch) > 0) {
-           line = lbuf_line(&cmdbuf);
-           save_input(line);
-           lbuf_init(&cmdbuf);
-       }
+       if (ch != '\r')
+           save_input(ch);
        if (auxfp)
            putc(ch, auxfp);
     }
index 330260f7f2d7fa2fce6a0841f6f74615a8e087a2..c2e3cd24b5c58d517b3d025d6ccec8441c4f9aa1 100644 (file)
@@ -27,7 +27,7 @@
  *  secure.c: Check redir etc. to protect against tampering deity
  *
  *  Known contributors to this file:
- *     Markus Armbruster, 2007-2015
+ *     Markus Armbruster, 2007-2017
  */
 
 #include <config.h>
 static struct ring recent_input;
 
 /*
- * Remember line of input @inp for a while.
- * It must end with a newline.
+ * Remember input @inp for a while.
  */
 void
-save_input(char *inp)
+save_input(char inp)
 {
-    size_t len = strlen(inp);
     int eol;
 
-    assert(len && inp[len - 1] == '\n');
-
-    while (ring_putm(&recent_input, inp, len) < 0) {
+    while (ring_putc(&recent_input, inp) < 0) {
        eol = ring_search(&recent_input, "\n", 0);
        assert(eol >= 0);
        ring_discard(&recent_input, eol + 1);
index 8e4454f9636eee10c59e53057c454dec6d9cb40b..c5462f681530a110f49fd1650bb2c0a5db0ca461 100644 (file)
@@ -27,7 +27,7 @@
  *  secure.h: Check redir etc. to protect against tampering deity
  *
  *  Known contributors to this file:
- *     Markus Armbruster, 2007-2009
+ *     Markus Armbruster, 2007-2017
  */
 
 #ifndef SECURE_H
@@ -35,7 +35,7 @@
 
 #include <stddef.h>
 
-extern void save_input(char *);
+extern void save_input(char);
 extern int seen_input(char *);
 extern int seen_exec_input(char *);