Eliminate ttynvt_t::tmp_buf

ttynvt_read() and _read_net() both used this buffer which could cause
things to mess up entirely.
This commit is contained in:
Kim Woelders
2018-10-17 10:29:23 +02:00
parent 86aebe372e
commit 1e05632ec0
+9 -9
View File
@@ -65,7 +65,6 @@ typedef struct {
char net_buf[NET_BUF_SIZE]; char net_buf[NET_BUF_SIZE];
int net_cnt; int net_cnt;
char tmp_buf[TMP_BUF_SIZE];
struct termios tio; struct termios tio;
@@ -226,6 +225,7 @@ static void _update_notify(ttynvt_t * tty, struct fuse_pollhandle *ph)
static void *_read_net(void *arg) static void *_read_net(void *arg)
{ {
ttynvt_t *tty = (ttynvt_t *) arg; ttynvt_t *tty = (ttynvt_t *) arg;
char buf[TMP_BUF_SIZE];
int res; int res;
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
@@ -283,14 +283,14 @@ static void *_read_net(void *arg)
if (tty->fds[FD_MASTER].revents & POLLIN) if (tty->fds[FD_MASTER].revents & POLLIN)
{ {
res = read(tty->fds[FD_MASTER].fd, tty->tmp_buf, TMP_BUF_SIZE); res = read(tty->fds[FD_MASTER].fd, buf, TMP_BUF_SIZE);
if (res < 0) if (res < 0)
{ {
_log(LOG_ERR, "master read error: %m\n"); _log(LOG_ERR, "master read error: %m\n");
break; break;
} }
DBG2_BUF("TtyM in ", tty->tmp_buf, res); DBG2_BUF("TtyM in ", buf, res);
telnet_tx(tty->tn, tty->tmp_buf, res); telnet_tx(tty->tn, buf, res);
} }
if (tty->fds[FD_SLAVE].revents & POLLIN) if (tty->fds[FD_SLAVE].revents & POLLIN)
@@ -546,6 +546,7 @@ ttynvt_read(fuse_req_t req, size_t size, off_t off,
struct fuse_file_info *info) struct fuse_file_info *info)
{ {
ttynvt_t *tty = (ttynvt_t *) (uintptr_t) info->fh; ttynvt_t *tty = (ttynvt_t *) (uintptr_t) info->fh;
char buf[TMP_BUF_SIZE];
int res; int res;
DBG2("%s\n", __func__); DBG2("%s\n", __func__);
@@ -557,7 +558,7 @@ ttynvt_read(fuse_req_t req, size_t size, off_t off,
{ {
_log(LOG_WARNING, "Rx EPIPE\n"); _log(LOG_WARNING, "Rx EPIPE\n");
tty->epipe = 1; tty->epipe = 1;
fuse_reply_buf(req, tty->tmp_buf, 0); fuse_reply_buf(req, NULL, 0);
} }
else else
fuse_reply_err(req, EBADFD); fuse_reply_err(req, EBADFD);
@@ -569,8 +570,7 @@ ttynvt_read(fuse_req_t req, size_t size, off_t off,
size = TMP_BUF_SIZE; size = TMP_BUF_SIZE;
fuse_req_interrupt_func(req, ttynvt_interrupted, (void *)pthread_self()); fuse_req_interrupt_func(req, ttynvt_interrupted, (void *)pthread_self());
res = res = _is_interrupted ? -2 : read(tty->fds[FD_SLAVE].fd, buf, size);
_is_interrupted ? -2 : read(tty->fds[FD_SLAVE].fd, tty->tmp_buf, size);
_is_interrupted = 0; _is_interrupted = 0;
tty->n_fds = 3; /* Enable polling of Slave */ tty->n_fds = 3; /* Enable polling of Slave */
fuse_req_interrupt_func(req, NULL, NULL); fuse_req_interrupt_func(req, NULL, NULL);
@@ -582,9 +582,9 @@ ttynvt_read(fuse_req_t req, size_t size, off_t off,
} }
DBG2("%s: fd=%d: sz=%u/%u: '%.*s'\n", __func__, DBG2("%s: fd=%d: sz=%u/%u: '%.*s'\n", __func__,
tty->fds[FD_SLAVE].fd, res, (int)size, res, tty->tmp_buf); tty->fds[FD_SLAVE].fd, res, (int)size, res, buf);
fuse_reply_buf(req, tty->tmp_buf, res); fuse_reply_buf(req, buf, res);
} }
static void static void