mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-10 01:48:00 +00:00
do_telnet_read: replace ad-hoc strbuf-alike with strbuf.
The ADDTOBUF macro and the three outbuf variables are trying to be a strbuf, and not doing it as well as the real one. Since c_write takes an int length parameter but outbuf->len is now a size_t, I've also arranged to flush outbuf periodically during the function, just in case it gets too big.
This commit is contained in:
parent
bd84c5e4b3
commit
26beafe984
26
telnet.c
26
telnet.c
@ -508,16 +508,7 @@ static void process_subneg(Telnet *telnet)
|
|||||||
|
|
||||||
static void do_telnet_read(Telnet *telnet, char *buf, int len)
|
static void do_telnet_read(Telnet *telnet, char *buf, int len)
|
||||||
{
|
{
|
||||||
char *outbuf = NULL;
|
strbuf *outbuf = strbuf_new();
|
||||||
int outbuflen = 0, outbufsize = 0;
|
|
||||||
|
|
||||||
#define ADDTOBUF(c) do { \
|
|
||||||
if (outbuflen >= outbufsize) { \
|
|
||||||
outbufsize = outbuflen + 256; \
|
|
||||||
outbuf = sresize(outbuf, outbufsize, char); \
|
|
||||||
} \
|
|
||||||
outbuf[outbuflen++] = (c); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
while (len--) {
|
while (len--) {
|
||||||
int c = (unsigned char) *buf++;
|
int c = (unsigned char) *buf++;
|
||||||
@ -531,7 +522,7 @@ static void do_telnet_read(Telnet *telnet, char *buf, int len)
|
|||||||
telnet->state = SEENIAC;
|
telnet->state = SEENIAC;
|
||||||
else {
|
else {
|
||||||
if (!telnet->in_synch)
|
if (!telnet->in_synch)
|
||||||
ADDTOBUF(c);
|
put_byte(outbuf, c);
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
/* I can't get the F***ing winsock to insert the urgent IAC
|
/* I can't get the F***ing winsock to insert the urgent IAC
|
||||||
@ -568,7 +559,7 @@ static void do_telnet_read(Telnet *telnet, char *buf, int len)
|
|||||||
} else {
|
} else {
|
||||||
/* ignore everything else; print it if it's IAC */
|
/* ignore everything else; print it if it's IAC */
|
||||||
if (c == IAC) {
|
if (c == IAC) {
|
||||||
ADDTOBUF(c);
|
put_byte(outbuf, c);
|
||||||
}
|
}
|
||||||
telnet->state = TOP_LEVEL;
|
telnet->state = TOP_LEVEL;
|
||||||
}
|
}
|
||||||
@ -617,11 +608,16 @@ static void do_telnet_read(Telnet *telnet, char *buf, int len)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (outbuf->len >= 4096) {
|
||||||
|
c_write(telnet, outbuf->u, outbuf->len);
|
||||||
|
outbuf->len = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outbuflen)
|
if (outbuf->len)
|
||||||
c_write(telnet, outbuf, outbuflen);
|
c_write(telnet, outbuf->u, outbuf->len);
|
||||||
sfree(outbuf);
|
strbuf_free(outbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void telnet_log(Plug *plug, int type, SockAddr *addr, int port,
|
static void telnet_log(Plug *plug, int type, SockAddr *addr, int port,
|
||||||
|
Loading…
Reference in New Issue
Block a user