Fix `telnet-resize-iac'. (IAC bytes were not duplicated when they
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Thu, 2 Jan 2003 11:14:35 +0000 (11:14 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Thu, 2 Jan 2003 11:14:35 +0000 (11:14 +0000)
occurred in a NAWS subnegotiation. Result: a terminal width or
height of 255 was not being correctly sent to the server.)

git-svn-id: svn://svn.tartarus.org/sgt/putty@2421 cda61777-01e9-0310-a592-d414129be87e

telnet.c

index 9d82509..592a2bb 100644 (file)
--- a/telnet.c
+++ b/telnet.c
@@ -786,7 +786,8 @@ static int telnet_sendbuffer(void *handle)
 static void telnet_size(void *handle, int width, int height)
 {
     Telnet telnet = (Telnet) handle;
-    unsigned char b[16];
+    unsigned char b[24];
+    int n;
     char *logbuf;
 
     telnet->term_width = width;
@@ -794,19 +795,23 @@ static void telnet_size(void *handle, int width, int height)
 
     if (telnet->s == NULL || telnet->opt_states[o_naws.index] != ACTIVE)
        return;
-    b[0] = IAC;
-    b[1] = SB;
-    b[2] = TELOPT_NAWS;
-    b[3] = telnet->term_width >> 8;
-    b[4] = telnet->term_width & 0xFF;
-    b[5] = telnet->term_height >> 8;
-    b[6] = telnet->term_height & 0xFF;
-    b[7] = IAC;
-    b[8] = SE;
-    telnet->bufsize = sk_write(telnet->s, b, 9);
+    n = 0;
+    b[n++] = IAC;
+    b[n++] = SB;
+    b[n++] = TELOPT_NAWS;
+    b[n++] = telnet->term_width >> 8;
+    if (b[n-1] == IAC) b[n++] = IAC;   /* duplicate any IAC byte occurs */
+    b[n++] = telnet->term_width & 0xFF;
+    if (b[n-1] == IAC) b[n++] = IAC;   /* duplicate any IAC byte occurs */
+    b[n++] = telnet->term_height >> 8;
+    if (b[n-1] == IAC) b[n++] = IAC;   /* duplicate any IAC byte occurs */
+    b[n++] = telnet->term_height & 0xFF;
+    if (b[n-1] == IAC) b[n++] = IAC;   /* duplicate any IAC byte occurs */
+    b[n++] = IAC;
+    b[n++] = SE;
+    telnet->bufsize = sk_write(telnet->s, b, n);
     logbuf = dupprintf("client:\tSB NAWS %d,%d",
-                      ((unsigned char) b[3] << 8) + (unsigned char) b[4],
-                      ((unsigned char) b[5] << 8) + (unsigned char) b[6]);
+                      telnet->term_width, telnet->term_height);
     logevent(telnet->frontend, logbuf);
     sfree(logbuf);
 }