diff options
-rw-r--r-- | accel-pppd/cli/tcp.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/accel-pppd/cli/tcp.c b/accel-pppd/cli/tcp.c index da28ff72..48fa01a2 100644 --- a/accel-pppd/cli/tcp.c +++ b/accel-pppd/cli/tcp.c @@ -144,7 +144,7 @@ static int cln_read(struct triton_md_handler_t *h) char *d; while (1) { - n = read(h->fd, cln->cmdline + cln->recv_pos, RECV_BUF_SIZE - cln->recv_pos); + n = read(h->fd, cln->cmdline + cln->recv_pos, RECV_BUF_SIZE - 1 - cln->recv_pos); if (n == 0) break; if (n < 0) { @@ -154,11 +154,12 @@ static int cln_read(struct triton_md_handler_t *h) } cln->recv_pos += n; - + cln->cmdline[cln->recv_pos] = '\0'; + while (cln->recv_pos) { d = strchr((char *)cln->cmdline, '\n'); if (!d) { - if (cln->recv_pos == RECV_BUF_SIZE) { + if (cln->recv_pos == RECV_BUF_SIZE - 1) { log_warn("cli: tcp: recv buffer overflow\n"); goto drop; } |