Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the limit of 1024 chars for input/output of add_cr() and escape_telnet() #1051

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
20 changes: 2 additions & 18 deletions src/dcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,6 @@ static int detect_telnet(unsigned char *buf)
return 0;
}

/* Escape telnet IAC and prepend CR to LF */
static char *escape_telnet(char *s)
{
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')
*p++ = '\r';
*p = 0;

return buf;
}

static void strip_telnet(int sock, char *buf, int *len)
{
unsigned char *p = (unsigned char *) buf, *o = (unsigned char *) buf;
Expand Down Expand Up @@ -969,7 +953,7 @@ static void out_dcc_general(int idx, char *buf, void *x)

strip_mirc_codes(p->strip_flags, buf);
if (dcc[idx].status & STAT_TELNET)
y = escape_telnet(buf);
y = add_cr(buf, 1);
if (dcc[idx].status & STAT_PAGE)
append_line(idx, y);
else
Expand Down Expand Up @@ -1827,7 +1811,7 @@ 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[1030];
egg_snprintf(buf, sizeof buf, "\n%s%s\r\n", escape_telnet(DCC_ENTERPASS),
egg_snprintf(buf, sizeof buf, "\n%s%s\r\n", add_cr(DCC_ENTERPASS, 1),
TLN_IAC_C TLN_WILL_C TLN_ECHO_C);
tputs(dcc[idx].sock, buf, strlen(buf));
} else
Expand Down
17 changes: 1 addition & 16 deletions src/dccutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,6 @@ int findanyidx(int z)
return -1;
}

/* Replace \n with \r\n */
char *add_cr(char *buf)
{
static char WBUF[1024];
char *p, *q;

for (p = buf, q = WBUF; *p; p++, q++) {
if (*p == '\n')
*q++ = '\r';
*q = *p;
}
*q = *p;
return WBUF;
}

extern void (*qserver) (int, char *, int);

ATTRIBUTE_FORMAT(printf,2,3)
Expand Down Expand Up @@ -204,7 +189,7 @@ void dprint(int idx, char *buf, int len)
len = LOGLINEMAX-10;
}
if (dcc[idx].type && ((long) (dcc[idx].type->output) == 1)) {
char *p = add_cr(buf);
char *p = add_cr(buf, 0);

tputs(dcc[idx].sock, p, strlen(p));
} else if (dcc[idx].type && dcc[idx].type->output)
Expand Down
25 changes: 25 additions & 0 deletions src/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1590,3 +1590,28 @@ int crypto_verify(const char *x_, const char *y_)
}
return (1 & ((d - 1) >> 8)) - 1;
}

/* Prepend CR to LF (Replace \n with \r\n) and escape telnet IAC if
* escape_telnet is set
*/
char *add_cr(const char *p, const int escape_telnet)
{
size_t len;
static size_t buf_size = 0;
static char *buf;
char *q;

len = (strlen(p) << 1) + 1;
if (len > buf_size) {
buf_size = len;
buf = nrealloc(buf, buf_size);
}
for (q = buf; *p; *q++ = *p++) {
if (escape_telnet && ((unsigned char) *p == TLN_IAC))
*q++ = *p;
else if (*p == '\n')
*q++ = '\r';
}
*q = 0;
return buf;
}
2 changes: 1 addition & 1 deletion src/proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ int dcc_fingerprint(int);
int increase_socks_max(void);
int findidx(int);
int findanyidx(int);
char *add_cr(char *);
void dprint(int, char *, int);
void dprintf (int, const char *format, ...) ATTRIBUTE_FORMAT(printf,2,3);
void chatout (const char *format, ...) ATTRIBUTE_FORMAT(printf,1,2);
Expand Down Expand Up @@ -267,6 +266,7 @@ void maskaddr(const char *, char *, int);
#define maskhost(a,b) maskaddr((a),(b),3)
#define maskban(a,b) maskaddr((a),(b),3)
int crypto_verify(const char *, const char *);
char *add_cr(const char *, const int);

/* net.c */
IP my_atoul(char *);
Expand Down