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:
parent
5cb14f508e
commit
cf7d52fc10
3 changed files with 8 additions and 23 deletions
|
@ -404,21 +404,13 @@ recv_output(int sock)
|
||||||
static int
|
static int
|
||||||
recv_input(int fd, struct ring *inbuf)
|
recv_input(int fd, struct ring *inbuf)
|
||||||
{
|
{
|
||||||
static struct lbuf cmdbuf;
|
|
||||||
int n, i, ch;
|
int n, i, ch;
|
||||||
char *line;
|
|
||||||
int res = 1;
|
int res = 1;
|
||||||
|
|
||||||
n = ring_from_file(inbuf, fd);
|
n = ring_from_file(inbuf, fd);
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (n == 0) {
|
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.
|
* Can't put EOF cookie into INBUF here, it may not fit.
|
||||||
* Leave it to caller.
|
* Leave it to caller.
|
||||||
|
@ -430,11 +422,8 @@ recv_input(int fd, struct ring *inbuf)
|
||||||
for (i = -n; i < 0; i++) {
|
for (i = -n; i < 0; i++) {
|
||||||
ch = ring_peek(inbuf, i);
|
ch = ring_peek(inbuf, i);
|
||||||
assert(ch != EOF);
|
assert(ch != EOF);
|
||||||
if (ch != '\r' && lbuf_putc(&cmdbuf, ch) > 0) {
|
if (ch != '\r')
|
||||||
line = lbuf_line(&cmdbuf);
|
save_input(ch);
|
||||||
save_input(line);
|
|
||||||
lbuf_init(&cmdbuf);
|
|
||||||
}
|
|
||||||
if (auxfp)
|
if (auxfp)
|
||||||
putc(ch, auxfp);
|
putc(ch, auxfp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
* secure.c: Check redir etc. to protect against tampering deity
|
* secure.c: Check redir etc. to protect against tampering deity
|
||||||
*
|
*
|
||||||
* Known contributors to this file:
|
* Known contributors to this file:
|
||||||
* Markus Armbruster, 2007-2015
|
* Markus Armbruster, 2007-2017
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
@ -42,18 +42,14 @@
|
||||||
static struct ring recent_input;
|
static struct ring recent_input;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Remember line of input @inp for a while.
|
* Remember input @inp for a while.
|
||||||
* It must end with a newline.
|
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
save_input(char *inp)
|
save_input(char inp)
|
||||||
{
|
{
|
||||||
size_t len = strlen(inp);
|
|
||||||
int eol;
|
int eol;
|
||||||
|
|
||||||
assert(len && inp[len - 1] == '\n');
|
while (ring_putc(&recent_input, inp) < 0) {
|
||||||
|
|
||||||
while (ring_putm(&recent_input, inp, len) < 0) {
|
|
||||||
eol = ring_search(&recent_input, "\n", 0);
|
eol = ring_search(&recent_input, "\n", 0);
|
||||||
assert(eol >= 0);
|
assert(eol >= 0);
|
||||||
ring_discard(&recent_input, eol + 1);
|
ring_discard(&recent_input, eol + 1);
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
* secure.h: Check redir etc. to protect against tampering deity
|
* secure.h: Check redir etc. to protect against tampering deity
|
||||||
*
|
*
|
||||||
* Known contributors to this file:
|
* Known contributors to this file:
|
||||||
* Markus Armbruster, 2007-2009
|
* Markus Armbruster, 2007-2017
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SECURE_H
|
#ifndef SECURE_H
|
||||||
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
extern void save_input(char *);
|
extern void save_input(char);
|
||||||
extern int seen_input(char *);
|
extern int seen_input(char *);
|
||||||
extern int seen_exec_input(char *);
|
extern int seen_exec_input(char *);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue