Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions src/dcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,17 @@ static int detect_telnet(unsigned char *buf)
}

/* Escape telnet IAC and prepend CR to LF */
static char *escape_telnet(char *s)
static char *escape_telnet(char *restrict dst, const char *restrict src, size_t dstsize)
{
static char buf[1024];
char *p;

for (p = buf; *s && (p < (buf + sizeof(buf) - 2)); *p++ = *s++)
if ((unsigned char) *s == TLN_IAC)
*p++ = *s;
else if (*s == '\n')
for (p = dst; *src && (p < (dst + dstsize - 2)); *p++ = *src++)
if ((unsigned char) *src == TLN_IAC)
*p++ = *src;
else if (*src == '\n')
*p++ = '\r';
*p = 0;

return buf;
return dst;
}

static void strip_telnet(int sock, char *buf, int *len)
Expand Down Expand Up @@ -965,11 +963,14 @@ static void append_line(int idx, char *line)
static void out_dcc_general(int idx, char *buf, void *x)
{
struct chat_info *p = (struct chat_info *) x;
char *y = buf;
char dst[1024];
char *y;

strip_mirc_codes(p->strip_flags, buf);
if (dcc[idx].status & STAT_TELNET)
y = escape_telnet(buf);
if (dcc[idx].status & STAT_TELNET) {
y = escape_telnet(dst, buf, sizeof dst);
} else
y = buf;
if (dcc[idx].status & STAT_PAGE)
append_line(idx, y);
else
Expand Down Expand Up @@ -1826,8 +1827,9 @@ static void dcc_telnet_pass(int idx, int atr)

/* Turn off remote telnet echo (send IAC WILL ECHO). */
if (dcc[idx].status & STAT_TELNET) {
char buf[512];
snprintf(buf, sizeof buf, "\n%s%s\r\n", escape_telnet(DCC_ENTERPASS),
char dst[512], buf[512];
snprintf(buf, sizeof buf, "\n%s%s\r\n",
escape_telnet(dst, DCC_ENTERPASS, sizeof dst),
TLN_IAC_C TLN_WILL_C TLN_ECHO_C);
tputs(dcc[idx].sock, buf, strlen(buf));
} else
Expand Down
Loading