=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/telnet/telnet.c,v retrieving revision 1.18 retrieving revision 1.19 diff -c -r1.18 -r1.19 *** src/usr.bin/telnet/telnet.c 2003/11/08 19:17:29 1.18 --- src/usr.bin/telnet/telnet.c 2005/02/27 15:46:42 1.19 *************** *** 1,4 **** ! /* $OpenBSD: telnet.c,v 1.18 2003/11/08 19:17:29 jmc Exp $ */ /* $NetBSD: telnet.c,v 1.7 1996/02/28 21:04:15 thorpej Exp $ */ /* --- 1,4 ---- ! /* $OpenBSD: telnet.c,v 1.19 2005/02/27 15:46:42 otto Exp $ */ /* $NetBSD: telnet.c,v 1.7 1996/02/28 21:04:15 thorpej Exp $ */ /* *************** *** 446,452 **** #endif case TELOPT_XDISPLOC: /* X Display location */ ! if (env_getvalue((unsigned char *)"DISPLAY")) new_state_ok = 1; break; --- 446,452 ---- #endif case TELOPT_XDISPLOC: /* X Display location */ ! if (env_getvalue((unsigned char *)"DISPLAY", 0)) new_state_ok = 1; break; *************** *** 682,688 **** resettermname = 0; if (tnamep && tnamep != unknown) free(tnamep); ! if ((tname = (char *)env_getvalue((unsigned char *)"TERM")) && (setupterm(tname, 1, &errret) == OK)) { tnamep = mklist(ttytype, tname); } else { --- 682,688 ---- resettermname = 0; if (tnamep && tnamep != unknown) free(tnamep); ! if ((tname = (char *)env_getvalue((unsigned char *)"TERM", 0)) && (setupterm(tname, 1, &errret) == OK)) { tnamep = mklist(ttytype, tname); } else { *************** *** 859,865 **** unsigned char temp[50], *dp; int len; ! if ((dp = env_getvalue((unsigned char *)"DISPLAY")) == NULL) { /* * Something happened, we no longer have a DISPLAY * variable. So, turn off the option. --- 859,865 ---- unsigned char temp[50], *dp; int len; ! if ((dp = env_getvalue((unsigned char *)"DISPLAY", 0)) == NULL) { /* * Something happened, we no longer have a DISPLAY * variable. So, turn off the option. *************** *** 1331,1347 **** } ! unsigned char slc_reply[128]; ! unsigned char *slc_replyp; void slc_start_reply() { slc_replyp = slc_reply; ! *slc_replyp++ = IAC; ! *slc_replyp++ = SB; ! *slc_replyp++ = TELOPT_LINEMODE; ! *slc_replyp++ = LM_SLC; } void --- 1331,1355 ---- } ! static unsigned char slc_reply[2 * SUBBUFSIZE]; ! static unsigned char *slc_replyp; + unsigned char + slc_add(unsigned char ch) + { + if (slc_replyp == slc_reply + sizeof(slc_reply)) + return ch; + return *slc_replyp++ = ch; + } + void slc_start_reply() { slc_replyp = slc_reply; ! slc_add(IAC); ! slc_add(SB); ! slc_add(TELOPT_LINEMODE); ! slc_add(LM_SLC); } void *************** *** 1350,1361 **** unsigned char flags; cc_t value; { ! if ((*slc_replyp++ = func) == IAC) ! *slc_replyp++ = IAC; ! if ((*slc_replyp++ = flags) == IAC) ! *slc_replyp++ = IAC; ! if ((*slc_replyp++ = (unsigned char)value) == IAC) ! *slc_replyp++ = IAC; } void --- 1358,1373 ---- unsigned char flags; cc_t value; { ! if (slc_replyp + 6 >= slc_reply + sizeof(slc_reply)) { ! printf("slc_add_reply: not enough room\n"); ! return; ! } ! if (slc_add(func) == IAC) ! slc_add(IAC); ! if (slc_add(flags) == IAC) ! slc_add(IAC); ! if (slc_add((unsigned char)value) == IAC) ! slc_add(IAC); } void *************** *** 1363,1370 **** { int len; ! *slc_replyp++ = IAC; ! *slc_replyp++ = SE; len = slc_replyp - slc_reply; if (len <= 6) return; --- 1375,1387 ---- { int len; ! if (slc_replyp + 2 >= slc_reply + sizeof(slc_reply)) { ! printf("slc_end_reply: not enough room\n"); ! return; ! } ! ! slc_add(IAC); ! slc_add(SE); len = slc_replyp - slc_reply; if (len <= 6) return; *************** *** 1482,1493 **** } } ! #define OPT_REPLY_SIZE 256 ! unsigned char *opt_reply; ! unsigned char *opt_replyp; ! unsigned char *opt_replyend; void env_opt_start() { unsigned char *p; --- 1499,1517 ---- } } ! #define OPT_REPLY_SIZE (2 * SUBBUFSIZE) ! static unsigned char *opt_reply; ! static unsigned char *opt_replyp; ! static unsigned char *opt_replyend; void + opt_add(unsigned char ch) + { + if (opt_replyp == opt_replyend) + return; + *opt_replyp++ = ch; + } + void env_opt_start() { unsigned char *p; *************** *** 1506,1515 **** } opt_replyp = opt_reply; opt_replyend = opt_reply + OPT_REPLY_SIZE; ! *opt_replyp++ = IAC; ! *opt_replyp++ = SB; ! *opt_replyp++ = telopt_environ; ! *opt_replyp++ = TELQUAL_IS; } void --- 1530,1539 ---- } opt_replyp = opt_reply; opt_replyend = opt_reply + OPT_REPLY_SIZE; ! opt_add(IAC); ! opt_add(SB); ! opt_add(telopt_environ); ! opt_add(TELQUAL_IS); } void *************** *** 1541,1597 **** env_opt_add(ep); return; } ! vp = env_getvalue(ep); ! if (opt_replyp + (vp ? strlen((char *)vp) : 0) + ! strlen((char *)ep) + 6 > opt_replyend) { ! int len; unsigned char *p; ! opt_replyend += OPT_REPLY_SIZE; len = opt_replyend - opt_reply; p = (unsigned char *)realloc(opt_reply, len); ! if (p == NULL) free(opt_reply); - opt_reply = p; - if (opt_reply == NULL) { /*@*/ printf("env_opt_add: realloc() failed!!!\n"); opt_reply = opt_replyp = opt_replyend = NULL; return; } ! opt_replyp = opt_reply + len - (opt_replyend - opt_replyp); ! opt_replyend = opt_reply + len; } if (opt_welldefined((char *)ep)) #ifdef OLD_ENVIRON if (telopt_environ == TELOPT_OLD_ENVIRON) ! *opt_replyp++ = old_env_var; else #endif ! *opt_replyp++ = NEW_ENV_VAR; else ! *opt_replyp++ = ENV_USERVAR; for (;;) { while ((c = *ep++)) { switch(c&0xff) { case IAC: ! *opt_replyp++ = IAC; break; case NEW_ENV_VAR: case NEW_ENV_VALUE: case ENV_ESC: case ENV_USERVAR: ! *opt_replyp++ = ENV_ESC; break; } ! *opt_replyp++ = c; } if ((ep = vp)) { #ifdef OLD_ENVIRON if (telopt_environ == TELOPT_OLD_ENVIRON) ! *opt_replyp++ = old_env_value; else #endif ! *opt_replyp++ = NEW_ENV_VALUE; vp = NULL; } else break; --- 1565,1624 ---- env_opt_add(ep); return; } ! vp = env_getvalue(ep, 1); ! if (opt_replyp + 2 * (vp ? strlen((char *)vp) : 0) + ! 2 * strlen((char *)ep) + 6 > opt_replyend) { ! size_t len; unsigned char *p; ! len = opt_replyend - opt_reply; + len += OPT_REPLY_SIZE + 2 * strlen(ep); + if (vp) + len += 2 * strlen(vp); p = (unsigned char *)realloc(opt_reply, len); ! if (p == NULL) { free(opt_reply); /*@*/ printf("env_opt_add: realloc() failed!!!\n"); opt_reply = opt_replyp = opt_replyend = NULL; return; } ! opt_replyp = p + (opt_replyp - opt_reply); ! opt_replyend = p + len; ! opt_reply = p; } if (opt_welldefined((char *)ep)) #ifdef OLD_ENVIRON if (telopt_environ == TELOPT_OLD_ENVIRON) ! opt_add(old_env_var); else #endif ! opt_add(NEW_ENV_VAR); else ! opt_add(ENV_USERVAR); ! for (;;) { while ((c = *ep++)) { switch(c&0xff) { case IAC: ! opt_add(IAC); break; case NEW_ENV_VAR: case NEW_ENV_VALUE: case ENV_ESC: case ENV_USERVAR: ! opt_add(ENV_ESC); break; } ! opt_add(c); } if ((ep = vp)) { #ifdef OLD_ENVIRON if (telopt_environ == TELOPT_OLD_ENVIRON) ! opt_add(old_env_value); else #endif ! opt_add(NEW_ENV_VALUE); vp = NULL; } else break; *************** *** 1619,1626 **** len = opt_replyp - opt_reply + 2; if (emptyok || len > 6) { ! *opt_replyp++ = IAC; ! *opt_replyp++ = SE; if (NETROOM() > len) { ring_supply_data(&netoring, opt_reply, len); printsub('>', &opt_reply[2], len - 2); --- 1646,1653 ---- len = opt_replyp - opt_reply + 2; if (emptyok || len > 6) { ! opt_add(IAC); ! opt_add(SE); if (NETROOM() > len) { ring_supply_data(&netoring, opt_reply, len); printsub('>', &opt_reply[2], len - 2); *************** *** 2197,2203 **** send_will(TELOPT_LINEMODE, 1); send_will(TELOPT_NEW_ENVIRON, 1); send_do(TELOPT_STATUS, 1); ! if (env_getvalue((unsigned char *)"DISPLAY")) send_will(TELOPT_XDISPLOC, 1); if (binary) tel_enter_binary(binary); --- 2224,2230 ---- send_will(TELOPT_LINEMODE, 1); send_will(TELOPT_NEW_ENVIRON, 1); send_do(TELOPT_STATUS, 1); ! if (env_getvalue((unsigned char *)"DISPLAY", 0)) send_will(TELOPT_XDISPLOC, 1); if (binary) tel_enter_binary(binary);