Skip to content

Commit

Permalink
Rewrite dcc relay filter
Browse files Browse the repository at this point in the history
Patch by: michaelortmann
  • Loading branch information
michaelortmann authored and vanosg committed Dec 7, 2018
1 parent 770d53a commit 0380755
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 24 deletions.
56 changes: 32 additions & 24 deletions src/botnet.c
Expand Up @@ -1469,36 +1469,44 @@ static void eof_dcc_relaying(int idx)

static void dcc_relay(int idx, char *buf, int j)
{
unsigned char *p = (unsigned char *) buf;
int mark;
unsigned char *src, *dst;

for (j = 0; dcc[j].sock != dcc[idx].u.relay->sock ||
dcc[j].type != &DCC_RELAYING; j++);
/* If redirecting to a non-telnet user, swallow telnet codes and
* escape sequences. */
/* If redirecting to a non-telnet user, swallow telnet IAC, escape sequences
* and CR. */
if (!(dcc[j].status & STAT_TELNET)) {
while (*p != 0) {
while (*p != 255 && (*p != '\033' || *(p + 1) != '[') && *p != '\r' && *p)
p++; /* Search for IAC, escape sequences and CR. */
if (*p == 255) {
mark = 2;
if (!*(p + 1))
mark = 1; /* Bogus */
if ((*(p + 1) >= 251) || (*(p + 1) <= 254)) {
mark = 3;
if (!*(p + 2))
mark = 2; /* Bogus */
src = (unsigned char *) buf;
dst = (unsigned char *) buf;
while (*src) {
/* Search for IAC, escape sequences and CR. */
if (*src == TLN_IAC) {
src++;
if ((*src >= TLN_WILL) && (*src <= TLN_DONT)) {
src++;
if (*src)
src++;
}
strcpy((char *) p, (char *) (p + mark));
} else if (*p == '\033') {
unsigned char *e;

/* Search for the end of the escape sequence. */
for (e = p + 2; *e != 'm' && *e; e++);
strcpy((char *) p, (char *) (e + 1));
} else if (*p == '\r')
memmove(p, p + 1, strlen((char *)p + 1) + 1);
else if (*src)
src++;
} else if (*src == ESC) {
src++;
if (*src == '[') { /* CSI */
src++;
/* Search for the end of the escape sequence. */
while (*src && *src++ != 'm');
}
} else if (*src == '\r') /* CR */
src++;
else {
if (src > dst)
*dst = *src;
src++;
dst++;
}
}
if (src > dst)
*dst = 0;
if (!buf[0])
dprintf(-dcc[idx].u.relay->sock, " \n");
else
Expand Down
7 changes: 7 additions & 0 deletions src/eggdrop.h
Expand Up @@ -756,6 +756,13 @@ enum {
EGG_OPTION_UNSET = 2 /* Unset option(s). */
};

#define ESC 27 /* Oct 033
* Hex 1B
* Caret notation ^[
* Escape sequences \e
* \e is not supported in all compilers
*/

/* Telnet codes. See "TELNET Protocol Specification" (RFC 854) and
* "TELNET Echo Option" (RFC 875) for details. */

Expand Down

0 comments on commit 0380755

Please sign in to comment.