}
}
+/*
+ * The `software version' part of an SSH version string is required
+ * to contain no spaces or minus signs.
+ */
+static void ssh_fix_verstring(char *str)
+{
+ /* Eat "SSH-<protoversion>-". */
+ assert(*str == 'S'); str++;
+ assert(*str == 'S'); str++;
+ assert(*str == 'H'); str++;
+ assert(*str == '-'); str++;
+ while (*str && *str != '-') str++;
+ assert(*str == '-'); str++;
+
+ /* Convert minus signs and spaces in the remaining string into
+ * underscores. */
+ while (*str) {
+ if (*str == '-' || *str == ' ')
+ *str = '_';
+ str++;
+ }
+}
+
static int do_ssh_init(Ssh ssh, unsigned char c)
{
struct do_ssh_init_state {
ssh->rdpkt2_state.incoming_sequence = 0;
s->vstring[s->vslen] = 0;
- s->vstring[strcspn(s->vstring, "\r\n")] = '\0';/* remove EOL chars */
+ s->vstring[strcspn(s->vstring, "\015\012")] = '\0';/* remove EOL chars */
{
char *vlog;
vlog = snewn(20 + s->vslen, char);
crStop(0);
}
- if (s->proto2 && (ssh->cfg.sshprot >= 2 || !s->proto1)) {
- /*
- * Use v2 protocol.
- */
- char verstring[80], vlog[100];
- sprintf(verstring, "SSH-2.0-%s", sshver);
- SHA_Init(&ssh->exhashbase);
- /*
- * Hash our version string and their version string.
- */
- sha_string(&ssh->exhashbase, verstring, strlen(verstring));
- sha_string(&ssh->exhashbase, s->vstring, strcspn(s->vstring, "\r\n"));
- sprintf(vlog, "We claim version: %s", verstring);
- logevent(vlog);
- strcat(verstring, "\012");
- logevent("Using SSH protocol version 2");
- sk_write(ssh->s, verstring, strlen(verstring));
- ssh->protocol = ssh2_protocol;
- ssh2_protocol_setup(ssh);
- ssh->version = 2;
- ssh->s_rdpkt = ssh2_rdpkt;
- } else {
- /*
- * Use v1 protocol.
- */
- char verstring[80], vlog[100];
- sprintf(verstring, "SSH-%s-%s",
- (ssh_versioncmp(s->version, "1.5") <= 0 ? s->version : "1.5"),
- sshver);
- sprintf(vlog, "We claim version: %s", verstring);
- logevent(vlog);
- strcat(verstring, "\012");
-
- logevent("Using SSH protocol version 1");
+ {
+ char *verstring;
+
+ if (s->proto2 && (ssh->cfg.sshprot >= 2 || !s->proto1)) {
+ /*
+ * Construct a v2 version string.
+ */
+ verstring = dupprintf("SSH-2.0-%s\015\012", sshver);
+ ssh->version = 2;
+ } else {
+ /*
+ * Construct a v1 version string.
+ */
+ verstring = dupprintf("SSH-%s-%s\012",
+ (ssh_versioncmp(s->version, "1.5") <= 0 ?
+ s->version : "1.5"),
+ sshver);
+ ssh->version = 1;
+ }
+
+ ssh_fix_verstring(verstring);
+
+ if (ssh->version == 2) {
+ /*
+ * Hash our version string and their version string.
+ */
+ SHA_Init(&ssh->exhashbase);
+ sha_string(&ssh->exhashbase, verstring,
+ strcspn(verstring, "\015\012"));
+ sha_string(&ssh->exhashbase, s->vstring,
+ strcspn(s->vstring, "\015\012"));
+
+ /*
+ * Initialise SSHv2 protocol.
+ */
+ ssh->protocol = ssh2_protocol;
+ ssh2_protocol_setup(ssh);
+ ssh->s_rdpkt = ssh2_rdpkt;
+ } else {
+ /*
+ * Initialise SSHv1 protocol.
+ */
+ ssh->protocol = ssh1_protocol;
+ ssh1_protocol_setup(ssh);
+ ssh->s_rdpkt = ssh1_rdpkt;
+ }
+ logeventf(ssh, "We claim version: %.*s",
+ strcspn(verstring, "\015\012"), verstring);
sk_write(ssh->s, verstring, strlen(verstring));
- ssh->protocol = ssh1_protocol;
- ssh1_protocol_setup(ssh);
- ssh->version = 1;
- ssh->s_rdpkt = ssh1_rdpkt;
+ sfree(verstring);
}
+
+ logeventf(ssh, "Using SSH protocol version %d", ssh->version);
+
update_specials_menu(ssh->frontend);
ssh->state = SSH_STATE_BEFORE_SIZE;
ssh->pinger = pinger_new(&ssh->cfg, &ssh_backend, ssh);
sfree(c);
}
freetree234(ssh->channels);
+ ssh->channels = NULL;
}
if (ssh->rportfwds) {
while ((pf = delpos234(ssh->rportfwds, 0)) != NULL)
sfree(pf);
freetree234(ssh->rportfwds);
+ ssh->rportfwds = NULL;
}
sfree(ssh->deferred_send_data);
if (ssh->x11auth)
if (ssh->s)
ssh_do_close(ssh);
expire_timer_context(ssh);
- sfree(ssh);
if (ssh->pinger)
pinger_free(ssh->pinger);
+ sfree(ssh);
random_unref();
}