Trim leading whitespace off the hostname if it's there.
[sgt/putty] / ssh.c
diff --git a/ssh.c b/ssh.c
index 9f0fe61..7470163 100644 (file)
--- a/ssh.c
+++ b/ssh.c
@@ -1505,7 +1505,8 @@ static int ssh_receive(Plug plug, int urgent, char *data, int len)
 /*
  * Connect to specified host and port.
  * Returns an error message, or NULL on success.
- * Also places the canonical host name into `realhost'.
+ * Also places the canonical host name into `realhost'. It must be
+ * freed by the caller.
  */
 static char *connect_to_host(char *host, int port, char **realhost)
 {
@@ -1545,7 +1546,7 @@ static char *connect_to_host(char *host, int port, char **realhost)
        return err;
 
 #ifdef FWHACK
-    *realhost = FWhost;
+    *realhost = strdup(FWhost);
 #endif
 
     /*
@@ -1782,7 +1783,8 @@ static int do_ssh1_login(unsigned char *in, int inlen, int ispkt)
                            break;
                          default:
                            if (((c >= ' ' && c <= '~') ||
-                                ((unsigned char) c >= 160)) && pos < 40) {
+                                ((unsigned char) c >= 160))
+                               && pos < sizeof(username)-1) {
                                username[pos++] = c;
                                c_write(&c, 1);
                            }
@@ -2017,7 +2019,10 @@ static int do_ssh1_login(unsigned char *in, int inlen, int ispkt)
                 * because one was supplied on the command line
                 * which has already failed to work). Terminate.
                 */
-               logevent("No more passwords to try");
+               send_packet(SSH1_MSG_DISCONNECT,
+                           PKT_STR, "No more passwords available to try",
+                           PKT_END);
+               connection_fatal("Unable to authenticate");
                ssh_state = SSH_STATE_CLOSED;
                crReturn(1);
            }
@@ -2049,9 +2054,7 @@ static int do_ssh1_login(unsigned char *in, int inlen, int ispkt)
                        exit(0);
                        break;
                      default:
-                       if (((c >= ' ' && c <= '~') ||
-                            ((unsigned char) c >= 160))
-                           && pos < sizeof(password))
+                       if (pos < sizeof(password)-1)
                            password[pos++] = c;
                        break;
                    }
@@ -3193,7 +3196,8 @@ static void do_ssh2_authconn(unsigned char *in, int inlen, int ispkt)
                            break;
                          default:
                            if (((c >= ' ' && c <= '~') ||
-                                ((unsigned char) c >= 160)) && pos < 40) {
+                                ((unsigned char) c >= 160))
+                               && pos < sizeof(username)-1) {
                                username[pos++] = c;
                                c_write(&c, 1);
                            }
@@ -3536,7 +3540,13 @@ static void do_ssh2_authconn(unsigned char *in, int inlen, int ispkt)
                         * command line which has already failed to
                         * work). Terminate.
                         */
-                       logevent("No more passwords to try");
+                       ssh2_pkt_init(SSH2_MSG_DISCONNECT);
+                       ssh2_pkt_adduint32(SSH2_DISCONNECT_BY_APPLICATION);
+                       ssh2_pkt_addstring
+                           ("No more passwords available to try");
+                       ssh2_pkt_addstring("en");       /* language tag */
+                       ssh2_pkt_send();
+                       connection_fatal("Unable to authenticate");
                        ssh_state = SSH_STATE_CLOSED;
                        crReturnV;
                    }
@@ -3572,9 +3582,7 @@ static void do_ssh2_authconn(unsigned char *in, int inlen, int ispkt)
                                exit(0);
                                break;
                              default:
-                               if (((c >= ' ' && c <= '~') ||
-                                    ((unsigned char) c >= 160))
-                                   && pos < 40)
+                               if (pos < sizeof(password)-1)
                                    password[pos++] = c;
                                break;
                            }