telnet: prevent SEGV if we are requested TELOPT_NEW_ENVIRON.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2010-04-27 08:54:24 +02:00
parent 6646de0214
commit 25b10d97e6

View File

@ -299,7 +299,7 @@ static void put_iac_subopt(byte c, char *str)
static void put_iac_subopt_autologin(void) static void put_iac_subopt_autologin(void)
{ {
int len = strlen(G.autologin) + 6; // (2 + 1 + 1 + strlen + 2) int len = strlen(G.autologin) + 6; // (2 + 1 + 1 + strlen + 2)
const char *user = "USER"; const char *p = "USER";
if (G.iaclen + len > IACBUFSIZE) if (G.iaclen + len > IACBUFSIZE)
iac_flush(); iac_flush();
@ -310,13 +310,14 @@ static void put_iac_subopt_autologin(void)
put_iac(TELQUAL_IS); put_iac(TELQUAL_IS);
put_iac(NEW_ENV_VAR); put_iac(NEW_ENV_VAR);
while (*user) while (*p)
put_iac(*user++); put_iac(*p++);
put_iac(NEW_ENV_VALUE); put_iac(NEW_ENV_VALUE);
while (*G.autologin) p = G.autologin;
put_iac(*G.autologin++); while (*p)
put_iac(*p++);
put_iac(IAC); put_iac(IAC);
put_iac(SE); put_iac(SE);
@ -441,7 +442,6 @@ static void to_sga(void)
static void to_ttype(void) static void to_ttype(void)
{ {
/* Tell server we will (or won't) do TTYPE */ /* Tell server we will (or won't) do TTYPE */
if (G.ttype) if (G.ttype)
put_iac2(WILL, TELOPT_TTYPE); put_iac2(WILL, TELOPT_TTYPE);
else else
@ -453,7 +453,6 @@ static void to_ttype(void)
static void to_new_environ(void) static void to_new_environ(void)
{ {
/* Tell server we will (or will not) do AUTOLOGIN */ /* Tell server we will (or will not) do AUTOLOGIN */
if (G.autologin) if (G.autologin)
put_iac2(WILL, TELOPT_NEW_ENVIRON); put_iac2(WILL, TELOPT_NEW_ENVIRON);
else else
@ -505,12 +504,12 @@ static int subneg(byte c)
G.telstate = TS_SUB2; G.telstate = TS_SUB2;
#if ENABLE_FEATURE_TELNET_TTYPE #if ENABLE_FEATURE_TELNET_TTYPE
else else
if (c == TELOPT_TTYPE) if (c == TELOPT_TTYPE && G.ttype)
put_iac_subopt(TELOPT_TTYPE, G.ttype); put_iac_subopt(TELOPT_TTYPE, G.ttype);
#endif #endif
#if ENABLE_FEATURE_TELNET_AUTOLOGIN #if ENABLE_FEATURE_TELNET_AUTOLOGIN
else else
if (c == TELOPT_NEW_ENVIRON) if (c == TELOPT_NEW_ENVIRON && G.autologin)
put_iac_subopt_autologin(); put_iac_subopt_autologin();
#endif #endif
break; break;