aboutsummaryrefslogtreecommitdiffstats
path: root/usr.bin/telnet/telnet.c
diff options
context:
space:
mode:
authorJacques Vidrine <nectar@FreeBSD.org>2005-03-28 15:58:28 +0000
committerJacques Vidrine <nectar@FreeBSD.org>2005-03-28 15:58:28 +0000
commit04293d7d1ade5be5987bb1be9d46947aef3b8ac4 (patch)
tree87659b064f50538a7205d2ca96122386acf6f2c1 /usr.bin/telnet/telnet.c
parenta84f9c8c4d27b7ce34314e6eed0a53ace0abe1dd (diff)
downloadsrc-04293d7d1ade5be5987bb1be9d46947aef3b8ac4.tar.gz
src-04293d7d1ade5be5987bb1be9d46947aef3b8ac4.zip
MFC src/contrib/telnet/telnet.c 1.16: Correct buffer overflows in
telnet(1). Security: CAN-2005-0468, CAN-2005-0469 Approved by: security-officer
Notes
Notes: svn path=/releng/4.11/; revision=144235
Diffstat (limited to 'usr.bin/telnet/telnet.c')
-rw-r--r--usr.bin/telnet/telnet.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/usr.bin/telnet/telnet.c b/usr.bin/telnet/telnet.c
index a570a8609680..c450a394d496 100644
--- a/usr.bin/telnet/telnet.c
+++ b/usr.bin/telnet/telnet.c
@@ -1193,6 +1193,7 @@ slc_check(void)
}
unsigned char slc_reply[128];
+unsigned char const * const slc_reply_eom = &slc_reply[sizeof(slc_reply)];
unsigned char *slc_replyp;
void
@@ -1208,6 +1209,14 @@ slc_start_reply(void)
void
slc_add_reply(unsigned char func, unsigned char flags, cc_t value)
{
+ /* A sequence of up to 6 bytes my be written for this member of the SLC
+ * suboption list by this function. The end of negotiation command,
+ * which is written by slc_end_reply(), will require 2 additional
+ * bytes. Do not proceed unless there is sufficient space for these
+ * items.
+ */
+ if (&slc_replyp[6+2] > slc_reply_eom)
+ return;
if ((*slc_replyp++ = func) == IAC)
*slc_replyp++ = IAC;
if ((*slc_replyp++ = flags) == IAC)
@@ -1221,6 +1230,9 @@ slc_end_reply(void)
{
int len;
+ /* The end of negotiation command requires 2 bytes. */
+ if (&slc_replyp[2] > slc_reply_eom)
+ return;
*slc_replyp++ = IAC;
*slc_replyp++ = SE;
len = slc_replyp - slc_reply;
@@ -1338,8 +1350,8 @@ env_opt(unsigned char *buf, int len)
}
}
-#define OPT_REPLY_SIZE 256
-unsigned char *opt_reply;
+#define OPT_REPLY_SIZE (2 * SUBBUFSIZE)
+unsigned char *opt_reply = NULL;
unsigned char *opt_replyp;
unsigned char *opt_replyend;
@@ -1392,9 +1404,9 @@ env_opt_add(unsigned char *ep)
return;
}
vp = env_getvalue(ep);
- if (opt_replyp + (vp ? strlen((char *)vp) : 0) +
- strlen((char *)ep) + 6 > opt_replyend)
- {
+ if (opt_replyp + (vp ? 2 * strlen((char *)vp) : 0) +
+ 2 * strlen((char *)ep) + 6 > opt_replyend)
+ {
int len;
opt_replyend += OPT_REPLY_SIZE;
len = opt_replyend - opt_reply;
@@ -1418,6 +1430,8 @@ env_opt_add(unsigned char *ep)
*opt_replyp++ = ENV_USERVAR;
for (;;) {
while ((c = *ep++)) {
+ if (opt_replyp + (2 + 2) > opt_replyend)
+ return;
switch(c&0xff) {
case IAC:
*opt_replyp++ = IAC;
@@ -1432,6 +1446,8 @@ env_opt_add(unsigned char *ep)
*opt_replyp++ = c;
}
if ((ep = vp)) {
+ if (opt_replyp + (1 + 2 + 2) > opt_replyend)
+ return;
#ifdef OLD_ENVIRON
if (telopt_environ == TELOPT_OLD_ENVIRON)
*opt_replyp++ = old_env_value;
@@ -1462,7 +1478,9 @@ env_opt_end(int emptyok)
{
int len;
- len = opt_replyp - opt_reply + 2;
+ if (opt_replyp + 2 > opt_replyend)
+ return;
+ len = opt_replyp + 2 - opt_reply;
if (emptyok || len > 6) {
*opt_replyp++ = IAC;
*opt_replyp++ = SE;