client: Simplify rogue redirection and execute protection further

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>
This commit is contained in:
Markus Armbruster 2017-06-18 18:57:28 +02:00
parent 5cb14f508e
commit cf7d52fc10
3 changed files with 8 additions and 23 deletions

View 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);
}