Browse Source

use a larger buffer, allocate it, and prevent overflowing recv buf..

tags/ggatessh-v1.0.0
John-Mark Gurney 3 years ago
parent
commit
657de5dd05
1 changed files with 19 additions and 3 deletions
  1. +19
    -3
      ggatec/ggatec.c

+ 19
- 3
ggatec/ggatec.c View File

@@ -95,10 +95,14 @@ send_thread(void *arg __unused)
{
struct g_gate_ctl_io ggio;
struct g_gate_hdr hdr;
char buf[MAXPHYS];
static char *buf;
ssize_t data;
int buflen = 1024*1024;
int error;

if (buf == NULL)
buf = malloc(buflen);

g_gate_log(LOG_NOTICE, "%s: started!", __func__);

ggio.gctl_version = G_GATE_VERSION;
@@ -106,7 +110,7 @@ send_thread(void *arg __unused)
ggio.gctl_data = buf;

for (;;) {
ggio.gctl_length = sizeof(buf);
ggio.gctl_length = buflen;
ggio.gctl_error = 0;
g_gate_ioctl(G_GATE_CMD_START, &ggio);
error = ggio.gctl_error;
@@ -203,9 +207,14 @@ recv_thread(void *arg __unused)
{
struct g_gate_ctl_io ggio;
struct g_gate_hdr hdr;
char buf[MAXPHYS];
static char *buf;
int buflen;
ssize_t data;

buflen = 1024*1024;
if (buf == NULL)
buf = malloc(buflen);

g_gate_log(LOG_NOTICE, "%s: started!", __func__);

ggio.gctl_version = G_GATE_VERSION;
@@ -233,6 +242,13 @@ recv_thread(void *arg __unused)
ggio.gctl_length = hdr.gh_length;
ggio.gctl_error = hdr.gh_error;

if (ggio.gctl_length > buflen) {
g_gate_log(LOG_ERR, "Received too large data, %llu.", ggio.gctl_length);
reconnect = 1;
pthread_kill(sendtd, SIGUSR1);
break;
}

if (ggio.gctl_error == 0 && ggio.gctl_cmd == GGATE_CMD_READ) {
data = g_gate_recv(recvfd, ggio.gctl_data,
ggio.gctl_length, MSG_WAITALL);


Loading…
Cancel
Save