summaryrefslogtreecommitdiff
path: root/common-session.c
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2015-02-28 09:06:40 +0800
committerMatt Johnston <matt@ucc.asn.au>2015-02-28 09:06:40 +0800
commitdef16fd87052cf80b08eb9e7a9ee621ed4c5cbcd (patch)
tree9cafa2212eed63a3757e4225d18a24042346a855 /common-session.c
parent0ae00730181d8645dd9f1df1205ca096eda5f6f0 (diff)
parent27330e8c7a129a060951061e10bfda0d836c44fa (diff)
downloaddropbear-def16fd87052cf80b08eb9e7a9ee621ed4c5cbcd.tar.gz
merge from default
Diffstat (limited to 'common-session.c')
-rw-r--r--common-session.c60
1 files changed, 45 insertions, 15 deletions
diff --git a/common-session.c b/common-session.c
index 46aef0d..19247a8 100644
--- a/common-session.c
+++ b/common-session.c
@@ -246,6 +246,15 @@ void session_loop(void(*loophandler)()) {
/* Not reached */
}
+static void cleanup_buf(buffer **buf) {
+ if (!*buf) {
+ return;
+ }
+ buf_burn(*buf);
+ buf_free(*buf);
+ *buf = NULL;
+}
+
/* clean up a session on exit */
void session_cleanup() {
@@ -257,24 +266,45 @@ void session_cleanup() {
return;
}
+ /* Beware of changing order of functions here. */
+
+ /* Must be before extra_session_cleanup() */
+ chancleanup();
+
if (ses.extra_session_cleanup) {
ses.extra_session_cleanup();
}
- chancleanup();
-
- /* Cleaning up keys must happen after other cleanup
- functions which might queue packets */
- if (ses.session_id) {
- buf_burn(ses.session_id);
- buf_free(ses.session_id);
- ses.session_id = NULL;
+ /* After these are freed most functions will exit */
+#ifdef DROPBEAR_CLEANUP
+ /* listeners call cleanup functions, this should occur before
+ other session state is freed. */
+ remove_all_listeners();
+
+ while (!isempty(&ses.writequeue)) {
+ buf_free(dequeue(&ses.writequeue));
}
- if (ses.hash) {
- buf_burn(ses.hash);
- buf_free(ses.hash);
- ses.hash = NULL;
+
+ m_free(ses.remoteident);
+ m_free(ses.authstate.pw_dir);
+ m_free(ses.authstate.pw_name);
+ m_free(ses.authstate.pw_shell);
+ m_free(ses.authstate.pw_passwd);
+ m_free(ses.authstate.username);
+#endif
+
+ cleanup_buf(&ses.session_id);
+ cleanup_buf(&ses.hash);
+ cleanup_buf(&ses.payload);
+ cleanup_buf(&ses.readbuf);
+ cleanup_buf(&ses.writepayload);
+ cleanup_buf(&ses.kexhashbuf);
+ cleanup_buf(&ses.transkexinit);
+ if (ses.dh_K) {
+ mp_clear(ses.dh_K);
}
+ m_free(ses.dh_K);
+
m_burn(ses.keys, sizeof(struct key_context));
m_free(ses.keys);
@@ -405,16 +435,16 @@ static int ident_readln(int fd, char* buf, int count) {
}
void ignore_recv_response() {
- // Do nothing
+ /* Do nothing */
TRACE(("Ignored msg_request_response"))
}
static void send_msg_keepalive() {
- CHECKCLEARTOWRITE();
time_t old_time_idle = ses.last_packet_time_idle;
-
struct Channel *chan = get_any_ready_channel();
+ CHECKCLEARTOWRITE();
+
if (chan) {
/* Channel requests are preferable, more implementations
handle them than SSH_MSG_GLOBAL_REQUEST */