X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/18524056e0153c37094cefe07ff8711a95897d6b..fe7af739e1f5585ba21fb052b75bc445a1f20166:/ssh.c diff --git a/ssh.c b/ssh.c index c97a2562..137e4607 100644 --- a/ssh.c +++ b/ssh.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "putty.h" #include "tree234.h" @@ -2701,6 +2702,9 @@ static int ssh_closing(Plug plug, const char *error_msg, int error_code, error_msg = "Server closed network connection"; } + if (ssh->close_expected && ssh->clean_exit && ssh->exitcode < 0) + ssh->exitcode = 0; + if (need_notify) notify_remote_exit(ssh->frontend); @@ -3560,6 +3564,7 @@ static int do_ssh1_login(Ssh ssh, unsigned char *in, int inlen, /* and try again */ } else { assert(0 && "unexpected return from loadrsakey()"); + got_passphrase = FALSE; /* placate optimisers */ } } @@ -4641,7 +4646,7 @@ static void ssh1_msg_channel_data(Ssh ssh, struct Packet *pktin) /* Data for an agent message. Buffer it. */ while (len > 0) { if (c->u.a.lensofar < 4) { - unsigned int l = min(4 - c->u.a.lensofar, len); + unsigned int l = min(4 - c->u.a.lensofar, (unsigned)len); memcpy(c->u.a.msglen + c->u.a.lensofar, p, l); p += l; @@ -4658,7 +4663,7 @@ static void ssh1_msg_channel_data(Ssh ssh, struct Packet *pktin) if (c->u.a.lensofar >= 4 && len > 0) { unsigned int l = min(c->u.a.totallen - c->u.a.lensofar, - len); + (unsigned)len); memcpy(c->u.a.message + c->u.a.lensofar, p, l); p += l; @@ -6078,7 +6083,8 @@ static void ssh2_msg_channel_data(Ssh ssh, struct Packet *pktin) case CHAN_AGENT: while (length > 0) { if (c->u.a.lensofar < 4) { - unsigned int l = min(4 - c->u.a.lensofar, length); + unsigned int l = min(4 - c->u.a.lensofar, + (unsigned)length); memcpy(c->u.a.msglen + c->u.a.lensofar, data, l); data += l; @@ -6095,7 +6101,7 @@ static void ssh2_msg_channel_data(Ssh ssh, struct Packet *pktin) if (c->u.a.lensofar >= 4 && length > 0) { unsigned int l = min(c->u.a.totallen - c->u.a.lensofar, - length); + (unsigned)length); memcpy(c->u.a.message + c->u.a.lensofar, data, l); data += l; @@ -6364,11 +6370,13 @@ static void ssh2_msg_channel_request(Ssh ssh, struct Packet *pktin) is_plausible = FALSE; } } + ssh->exitcode = 128; /* means `unknown signal' */ if (is_plausible) { if (is_int) { /* Old non-standard OpenSSH. */ int signum = ssh_pkt_getuint32(pktin); fmt_sig = dupprintf(" %d", signum); + ssh->exitcode = 128 + signum; } else { /* As per the drafts. */ char *sig; @@ -6380,6 +6388,82 @@ static void ssh2_msg_channel_request(Ssh ssh, struct Packet *pktin) fmt_sig = dupprintf(" \"%.*s\"", siglen, sig); } + + /* + * Really hideous method of translating the + * signal description back into a locally + * meaningful number. + */ + + if (0) + ; +#ifdef SIGABRT + else if (siglen == lenof("ABRT")-1 && + !memcmp(sig, "ABRT", siglen)) + ssh->exitcode = 128 + SIGABRT; +#endif +#ifdef SIGALRM + else if (siglen == lenof("ALRM")-1 && + !memcmp(sig, "ALRM", siglen)) + ssh->exitcode = 128 + SIGALRM; +#endif +#ifdef SIGFPE + else if (siglen == lenof("FPE")-1 && + !memcmp(sig, "FPE", siglen)) + ssh->exitcode = 128 + SIGFPE; +#endif +#ifdef SIGHUP + else if (siglen == lenof("HUP")-1 && + !memcmp(sig, "HUP", siglen)) + ssh->exitcode = 128 + SIGHUP; +#endif +#ifdef SIGILL + else if (siglen == lenof("ILL")-1 && + !memcmp(sig, "ILL", siglen)) + ssh->exitcode = 128 + SIGILL; +#endif +#ifdef SIGINT + else if (siglen == lenof("INT")-1 && + !memcmp(sig, "INT", siglen)) + ssh->exitcode = 128 + SIGINT; +#endif +#ifdef SIGKILL + else if (siglen == lenof("KILL")-1 && + !memcmp(sig, "KILL", siglen)) + ssh->exitcode = 128 + SIGKILL; +#endif +#ifdef SIGPIPE + else if (siglen == lenof("PIPE")-1 && + !memcmp(sig, "PIPE", siglen)) + ssh->exitcode = 128 + SIGPIPE; +#endif +#ifdef SIGQUIT + else if (siglen == lenof("QUIT")-1 && + !memcmp(sig, "QUIT", siglen)) + ssh->exitcode = 128 + SIGQUIT; +#endif +#ifdef SIGSEGV + else if (siglen == lenof("SEGV")-1 && + !memcmp(sig, "SEGV", siglen)) + ssh->exitcode = 128 + SIGSEGV; +#endif +#ifdef SIGTERM + else if (siglen == lenof("TERM")-1 && + !memcmp(sig, "TERM", siglen)) + ssh->exitcode = 128 + SIGTERM; +#endif +#ifdef SIGUSR1 + else if (siglen == lenof("USR1")-1 && + !memcmp(sig, "USR1", siglen)) + ssh->exitcode = 128 + SIGUSR1; +#endif +#ifdef SIGUSR2 + else if (siglen == lenof("USR2")-1 && + !memcmp(sig, "USR2", siglen)) + ssh->exitcode = 128 + SIGUSR2; +#endif + else + ssh->exitcode = 128; } core = ssh2_pkt_getbool(pktin); ssh_pkt_getstring(pktin, &msg, &msglen);