Skip to content

Commit 7afd957

Browse files
Fix writing to tls socket
Found by: https://github.com/michaelortmann/ Patch by: https://github.com/michaelortmann/
1 parent 0896e32 commit 7afd957

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

src/dcc.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,17 @@ static int detect_telnet(unsigned char *buf)
9090
}
9191

9292
/* Escape telnet IAC and prepend CR to LF */
93-
static char *escape_telnet(char *s)
93+
static char *escape_telnet(char *restrict dst, const char *restrict src, size_t dstsize)
9494
{
95-
static char buf[1024];
9695
char *p;
9796

98-
for (p = buf; *s && (p < (buf + sizeof(buf) - 2)); *p++ = *s++)
99-
if ((unsigned char) *s == TLN_IAC)
100-
*p++ = *s;
101-
else if (*s == '\n')
97+
for (p = dst; *src && (p < (dst + dstsize - 2)); *p++ = *src++)
98+
if ((unsigned char) *src == TLN_IAC)
99+
*p++ = *src;
100+
else if (*src == '\n')
102101
*p++ = '\r';
103102
*p = 0;
104-
105-
return buf;
103+
return dst;
106104
}
107105

108106
static void strip_telnet(int sock, char *buf, int *len)
@@ -959,11 +957,14 @@ static void append_line(int idx, char *line)
959957
static void out_dcc_general(int idx, char *buf, void *x)
960958
{
961959
struct chat_info *p = (struct chat_info *) x;
962-
char *y = buf;
960+
char dst[1024];
961+
char *y;
963962

964963
strip_mirc_codes(p->strip_flags, buf);
965-
if (dcc[idx].status & STAT_TELNET)
966-
y = escape_telnet(buf);
964+
if (dcc[idx].status & STAT_TELNET) {
965+
y = escape_telnet(dst, buf, sizeof dst);
966+
} else
967+
y = buf;
967968
if (dcc[idx].status & STAT_PAGE)
968969
append_line(idx, y);
969970
else
@@ -1842,8 +1843,9 @@ static void dcc_telnet_pass(int idx, int atr)
18421843

18431844
/* Turn off remote telnet echo (send IAC WILL ECHO). */
18441845
if (dcc[idx].status & (STAT_TELNET | STAT_WS)) {
1845-
char buf[512];
1846-
snprintf(buf, sizeof buf, "\n%s%s\r\n", escape_telnet(DCC_ENTERPASS),
1846+
char dst[506], buf[512];
1847+
snprintf(buf, sizeof buf, "\n%s%s\r\n",
1848+
escape_telnet(dst, DCC_ENTERPASS, sizeof dst),
18471849
TLN_IAC_C TLN_WILL_C TLN_ECHO_C);
18481850
tputs(dcc[idx].sock, buf, strlen(buf));
18491851
} else

0 commit comments

Comments
 (0)