Tweak to window handling: Keep the local window in a signed integer, and
authorben <ben@cda61777-01e9-0310-a592-d414129be87e>
Sat, 4 Aug 2007 14:32:06 +0000 (14:32 +0000)
committerben <ben@cda61777-01e9-0310-a592-d414129be87e>
Sat, 4 Aug 2007 14:32:06 +0000 (14:32 +0000)
arrange to handle usefully the case where the server sends us more data
than it's allowed to.  There's no danger of overflow, since the maximum is
OUR_V2_WINSIZE and the minimum is -OUR_V2_MAXPKT (at least if the server is
nice).

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

ssh.c

diff --git a/ssh.c b/ssh.c
index 3476d3d..4f69201 100644 (file)
--- a/ssh.c
+++ b/ssh.c
@@ -551,7 +551,8 @@ struct ssh_channel {
        struct ssh2_data_channel {
            bufchain outbuffer;
            unsigned remwindow, remmaxpkt;
-           unsigned locwindow;
+           /* locwindow is signed so we can cope with excess data. */
+           int locwindow;
        } v2;
     } v;
     union {
@@ -6284,9 +6285,12 @@ static void ssh2_msg_channel_data(Ssh ssh, struct Packet *pktin)
        /*
         * If we are not buffering too much data,
         * enlarge the window again at the remote side.
+        * If we are buffering too much, we may still
+        * need to adjust the window if the server's
+        * sent excess data.
         */
-       if (bufsize < OUR_V2_WINSIZE)
-           ssh2_set_window(c, OUR_V2_WINSIZE - bufsize);
+       ssh2_set_window(c, bufsize < OUR_V2_WINSIZE ?
+                       OUR_V2_WINSIZE - bufsize : 0);
     }
 }