# HG changeset patch # User Matt Johnston # Date 1425387180 -28800 # Node ID 23103e1e9548a1814d5ac28a423f9966152c1a60 # Parent 0b365b6a6f087968a2b6bfbf6d4f11ca78f19e21 Fix error handling for dbclient async connect diff -r 0b365b6a6f08 -r 23103e1e9548 cli-main.c --- a/cli-main.c Mon Mar 02 21:40:06 2015 +0800 +++ b/cli-main.c Tue Mar 03 20:53:00 2015 +0800 @@ -87,6 +87,7 @@ static void cli_dropbear_exit(int exitcode, const char* format, va_list param) { char fmtbuf[300]; + char exitmsg[500]; if (!sessinitdone) { snprintf(fmtbuf, sizeof(fmtbuf), "Exited: %s", @@ -98,12 +99,15 @@ cli_opts.remoteport, format); } + /* Arguments to the exit printout may be unsafe to use after session_cleanup() */ + vsnprintf(exitmsg, sizeof(exitmsg), fmtbuf, param); + /* Do the cleanup first, since then the terminal will be reset */ session_cleanup(); /* Avoid printing onwards from terminal cruft */ fprintf(stderr, "\n"); - _dropbear_log(LOG_INFO, fmtbuf, param); + dropbear_log(LOG_INFO, "%s", exitmsg);; exit(exitcode); } diff -r 0b365b6a6f08 -r 23103e1e9548 netio.c --- a/netio.c Mon Mar 02 21:40:06 2015 +0800 +++ b/netio.c Tue Mar 03 20:53:00 2015 +0800 @@ -104,6 +104,8 @@ message.msg_iovlen = iovlen; res = sendmsg(c->sock, &message, MSG_FASTOPEN); if (res < 0 && errno != EINPROGRESS) { + m_free(c->errstring); + c->errstring = m_strdup(strerror(errno)); /* Not entirely sure which kind of errors are normal - 2.6.32 seems to return EPIPE for any (nonblocking?) sendmsg(). just fall back */ TRACE(("sendmsg tcp_fastopen failed, falling back. %s", strerror(errno))); @@ -124,6 +126,8 @@ if (res < 0 && errno != EINPROGRESS) { /* failure */ + m_free(c->errstring); + c->errstring = m_strdup(strerror(errno)); close(c->sock); c->sock = -1; continue;