Skip to content

Commit fb17505

Browse files
Fix telnet echo and esc bold codes
1 parent 9bebb34 commit fb17505

File tree

4 files changed

+51
-20
lines changed

4 files changed

+51
-20
lines changed

src/dcc.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -737,10 +737,8 @@ static void dcc_chat_pass(int idx, char *buf, int atr)
737737
dcc[idx].u.chat->con_flags = (atr & USER_MASTER) ? conmask : 0;
738738
dcc[idx].u.chat->channel = -2;
739739
/* Turn echo back on for telnet sessions (send IAC WON'T ECHO). */
740-
if (dcc[idx].status & STAT_TELNET)
740+
if (dcc[idx].status & (STAT_TELNET | STAT_WS))
741741
tputs(dcc[idx].sock, TLN_IAC_C TLN_WONT_C TLN_ECHO_C "\n", 4);
742-
else if (dcc[idx].status & STAT_WS)
743-
tputs(dcc[idx].sock, WS_ECHO_ON, 1);
744742
dcc_chatter(idx);
745743
}
746744
} else {
@@ -1851,20 +1849,14 @@ static void dcc_telnet_pass(int idx, int atr)
18511849
* <Cybah>
18521850
*/
18531851

1854-
/* Turn off remote telnet echo */
1855-
char buf[512];
1856-
if (dcc[idx].status & STAT_TELNET) {
1857-
/* For telnet sessions send IAC WILL ECHO */
1852+
/* Turn off remote telnet echo (send IAC WILL ECHO). */
1853+
if (dcc[idx].status & (STAT_TELNET | STAT_WS)) {
1854+
char buf[512];
18581855
snprintf(buf, sizeof buf, "\n%s%s\r\n", escape_telnet(DCC_ENTERPASS),
18591856
TLN_IAC_C TLN_WILL_C TLN_ECHO_C);
18601857
tputs(dcc[idx].sock, buf, strlen(buf));
1861-
} else if (dcc[idx].status & STAT_WS) {
1862-
/* For webui sessions */
1863-
snprintf(buf, sizeof buf, "\n%s" WS_ECHO_OFF "\n", DCC_ENTERPASS);
1864-
tputs(dcc[idx].sock, buf, strlen(buf));
1865-
} else {
1858+
} else
18661859
dprintf(idx, "\n%s\n", DCC_ENTERPASS);
1867-
}
18681860
}
18691861
}
18701862

src/eggdrop.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,4 @@ struct dns_thread_node {
758758
extern struct dns_thread_node *dns_thread_head;
759759
#endif
760760

761-
#define WS_ECHO_ON "\x01" /* webui websocket echo on */
762-
#define WS_ECHO_OFF "\x02" /* webui websocket echo off */
763-
764761
#endif /* _EGG_EGGDROP_H */

src/misc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ static int display_tellhelp(int idx, char *file, FILE *f,
12181218

12191219
if (f) {
12201220
help_subst(NULL, NULL, 0,
1221-
(dcc[idx].status & STAT_TELNET) ? 0 : HELP_IRC, NULL);
1221+
(dcc[idx].status & (STAT_TELNET | STAT_WS)) ? 0 : HELP_IRC, NULL);
12221222
/* don't check for feof after fgets, skips last line if it has no \n (ie on windows) */
12231223
while (!feof(f) && fgets(s, HELP_BUF_LEN, f) != NULL) {
12241224
if (s[strlen(s) - 1] == '\n')
@@ -1309,7 +1309,7 @@ void sub_lang(int idx, char *text)
13091309

13101310
get_user_flagrec(dcc[idx].user, &fr, dcc[idx].u.chat->con_chan);
13111311
help_subst(NULL, NULL, 0,
1312-
(dcc[idx].status & STAT_TELNET) ? 0 : HELP_IRC, NULL);
1312+
(dcc[idx].status & (STAT_TELNET | STAT_WS)) ? 0 : HELP_IRC, NULL);
13131313
strlcpy(s, text, sizeof s);
13141314
if (s[strlen(s) - 1] == '\n')
13151315
s[strlen(s) - 1] = 0;
@@ -1350,7 +1350,7 @@ void show_motd(int idx)
13501350
dprintf(idx, "\n");
13511351
/* reset the help_subst variables to their defaults */
13521352
help_subst(NULL, NULL, 0,
1353-
(dcc[idx].status & STAT_TELNET) ? 0 : HELP_IRC, NULL);
1353+
(dcc[idx].status & (STAT_TELNET | STAT_WS)) ? 0 : HELP_IRC, NULL);
13541354
/* don't check for feof after fgets, skips last line if it has no \n (ie on windows) */
13551355
while (!feof(vv) && fgets(s, sizeof s, vv) != NULL) {
13561356
if (s[strlen(s) - 1] == '\n')

src/mod/webui.mod/webui.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#define WS_LEN 28 /* length of Sec-WebSocket-Accept header field value
4141
* base64(len(sha1))
4242
* import math; (4 * math.ceil(20 / 3)) */
43+
#define WS_ECHO_ON 0x01
44+
#define WS_ECHO_OFF 0x02
4345

4446
static Function *global = NULL;
4547

@@ -330,7 +332,7 @@ static size_t escape_html(char *dst, char *src, size_t size) {
330332
char *d = dst;
331333

332334
for (i = 0; i < size; i++) {
333-
switch (src[i]) {
335+
switch ((unsigned char) src[i]) {
334336
case '"':
335337
*d++ = '&';
336338
*d++ = 'q';
@@ -366,6 +368,45 @@ static size_t escape_html(char *dst, char *src, size_t size) {
366368
*d++ = 't';
367369
*d++ = ';';
368370
break;
371+
case ESC:
372+
// debug0("escape_html(): ESC");
373+
if ((i + 4) < size) {
374+
if ( ((unsigned char) src[i + 1] == '[') &&
375+
((unsigned char) src[i + 2] == '0') &&
376+
((unsigned char) src[i + 3] == 'm')) {
377+
*d++ = '<';
378+
*d++ = 'b';
379+
*d++ = '>';
380+
} else if (((unsigned char) src[i + 1] == '[') &&
381+
((unsigned char) src[i + 2] == '1') &&
382+
((unsigned char) src[i + 3] == 'm')) {
383+
*d++ = '<';
384+
*d++ = 'b';
385+
*d++ = '/';
386+
*d++ = '>';
387+
} else
388+
debug3("webui: escape_html(): unknown escape sequence found, skipping, %x %x %x, PLEASE REPORT THIS BUG",
389+
(unsigned char) src[i + 1], (unsigned char) src[i + 2], (unsigned char) src[i + 3]);
390+
i += 3;
391+
} else
392+
debug0("webui: escape_html(): unknown SHORT escape sequence found, skipping, PLEASE REPORT THIS BUG");
393+
break;
394+
case TLN_IAC:
395+
// debug0("escape_html(): TLN_IAC_C");
396+
if ((i + 2) < size) {
397+
if ( ((unsigned char) src[i + 1] == TLN_WILL) &&
398+
((unsigned char) src[i + 2] == TLN_ECHO))
399+
*d++ = WS_ECHO_OFF;
400+
else if (((unsigned char) src[i + 1] == TLN_WONT) &&
401+
((unsigned char) src[i + 2] == TLN_ECHO))
402+
*d++ = WS_ECHO_ON;
403+
else
404+
debug2("webui: escape_html(): unknown telnet command found, skipping, %x %x, PLEASE REPORT THIS BUG",
405+
(unsigned char) src[i + 1], (unsigned char) src[i + 2]);
406+
i += 2;
407+
} else
408+
debug0("webui: escape_html(): unknown SHORT telnet command found, skipping, PLEASE REPORT THIS BUG");
409+
break;
369410
default:
370411
*d++ = src[i];
371412
}
@@ -383,6 +424,7 @@ static size_t webui_frame(char **dst, char *src, size_t len) {
383424
len = escape_html(buf + 4, src, len);
384425
/* we must not use putlog() or debug() here or we get recursion */
385426
/* A server MUST NOT mask any frames that it sends to the client */
427+
/* we use text, not binary, so escape_html() must output valid html */
386428
if (len < 0x7e) {
387429
buf[2] =0x81; /* FIN + text frame */
388430
buf[3] = len;

0 commit comments

Comments
 (0)