Make sure we do notify_remote_exit(ssh->frontend) _before_
[u/mdw/putty] / ssh.c
diff --git a/ssh.c b/ssh.c
index b9d906d..7f3748a 100644 (file)
--- a/ssh.c
+++ b/ssh.c
@@ -2517,6 +2517,9 @@ static int ssh_closing(Plug plug, const char *error_msg, int error_code,
         error_msg = "Server unexpectedly closed network connection";
     }
 
+    if (need_notify)
+        notify_remote_exit(ssh->frontend);
+
     if (error_msg) {
        /* A socket error has occurred. */
        logevent(error_msg);
@@ -2524,8 +2527,6 @@ static int ssh_closing(Plug plug, const char *error_msg, int error_code,
     } else {
         logevent("Server closed network connection");
     }
-    if (need_notify)
-        notify_remote_exit(ssh->frontend);
     return 0;
 }
 
@@ -3911,7 +3912,7 @@ static void ssh_setup_portfwd(Ssh ssh, const Config *cfg)
                    strcpy(saddr, sports);
                n = 0;
            }
-           if (n < 255) sports[n++] = *portfwd_strptr++;
+           if (n < lenof(sports)-1) sports[n++] = *portfwd_strptr++;
        }
        sports[n] = 0;
        if (type != 'D') {
@@ -3919,14 +3920,14 @@ static void ssh_setup_portfwd(Ssh ssh, const Config *cfg)
                portfwd_strptr++;
            n = 0;
            while (*portfwd_strptr && *portfwd_strptr != ':') {
-               if (n < 255) host[n++] = *portfwd_strptr++;
+               if (n < lenof(host)-1) host[n++] = *portfwd_strptr++;
            }
            host[n] = 0;
            if (*portfwd_strptr == ':')
                portfwd_strptr++;
            n = 0;
            while (*portfwd_strptr) {
-               if (n < 255) dports[n++] = *portfwd_strptr++;
+               if (n < lenof(dports)-1) dports[n++] = *portfwd_strptr++;
            }
            dports[n] = 0;
            portfwd_strptr++;