OSDN Git Service

Specialize for gce targets in openssh am: eab54b0935
[android-x86/external-openssh.git] / mux.c
diff --git a/mux.c b/mux.c
index f3faaee..e6136fd 100644 (file)
--- a/mux.c
+++ b/mux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mux.c,v 1.50 2015/01/20 23:14:00 deraadt Exp $ */
+/* $OpenBSD: mux.c,v 1.54 2015/08/19 23:18:26 djm Exp $ */
 /*
  * Copyright (c) 2002-2008 Damien Miller <djm@openbsd.org>
  *
@@ -350,7 +350,7 @@ process_mux_new_session(u_int rid, Channel *c, Buffer *m, Buffer *r)
                        free(cp);
                        continue;
                }
-               cctx->env = xrealloc(cctx->env, env_len + 2,
+               cctx->env = xreallocarray(cctx->env, env_len + 2,
                    sizeof(*cctx->env));
                cctx->env[env_len++] = cp;
                cctx->env[env_len] = NULL;
@@ -593,7 +593,9 @@ mux_confirm_remote_forward(int type, u_int32_t seq, void *ctxt)
                return;
        }
        buffer_init(&out);
-       if (fctx->fid >= options.num_remote_forwards) {
+       if (fctx->fid >= options.num_remote_forwards ||
+           (options.remote_forwards[fctx->fid].connect_path == NULL &&
+           options.remote_forwards[fctx->fid].connect_host == NULL)) {
                xasprintf(&failmsg, "unknown forwarding id %d", fctx->fid);
                goto fail;
        }
@@ -605,7 +607,7 @@ mux_confirm_remote_forward(int type, u_int32_t seq, void *ctxt)
        if (type == SSH2_MSG_REQUEST_SUCCESS) {
                if (rfwd->listen_port == 0) {
                        rfwd->allocated_port = packet_get_int();
-                       logit("Allocated port %u for mux remote forward"
+                       debug("Allocated port %u for mux remote forward"
                            " to %s:%d", rfwd->allocated_port,
                            rfwd->connect_host, rfwd->connect_port);
                        buffer_put_int(&out, MUX_S_REMOTE_PORT);
@@ -627,6 +629,17 @@ mux_confirm_remote_forward(int type, u_int32_t seq, void *ctxt)
                else
                        xasprintf(&failmsg, "remote port forwarding failed for "
                            "listen port %d", rfwd->listen_port);
+
+                debug2("%s: clearing registered forwarding for listen %d, "
+                   "connect %s:%d", __func__, rfwd->listen_port,
+                   rfwd->connect_path ? rfwd->connect_path :
+                   rfwd->connect_host, rfwd->connect_port);
+
+               free(rfwd->listen_host);
+               free(rfwd->listen_path);
+               free(rfwd->connect_host);
+               free(rfwd->connect_path);
+               memset(rfwd, 0, sizeof(*rfwd));
        }
  fail:
        error("%s: %s", __func__, failmsg);
@@ -652,6 +665,8 @@ process_mux_open_fwd(u_int rid, Channel *c, Buffer *m, Buffer *r)
        u_int lport, cport;
        int i, ret = 0, freefwd = 1;
 
+       memset(&fwd, 0, sizeof(fwd));
+
        /* XXX - lport/cport check redundant */
        if (buffer_get_int_ret(&ftype, m) != 0 ||
            (listen_addr = buffer_get_string_ret(m, NULL)) == NULL ||
@@ -819,6 +834,8 @@ process_mux_close_fwd(u_int rid, Channel *c, Buffer *m, Buffer *r)
        int i, ret = 0;
        u_int lport, cport;
 
+       memset(&fwd, 0, sizeof(fwd));
+
        if (buffer_get_int_ret(&ftype, m) != 0 ||
            (listen_addr = buffer_get_string_ret(m, NULL)) == NULL ||
            buffer_get_int_ret(&lport, m) != 0 ||
@@ -1722,7 +1739,7 @@ mux_client_forward(int fd, int cancel_flag, u_int ftype, struct Forward *fwd)
                if (cancel_flag)
                        fatal("%s: got MUX_S_REMOTE_PORT for cancel", __func__);
                fwd->allocated_port = buffer_get_int(&m);
-               logit("Allocated port %u for remote forward to %s:%d",
+               verbose("Allocated port %u for remote forward to %s:%d",
                    fwd->allocated_port,
                    fwd->connect_host ? fwd->connect_host : "",
                    fwd->connect_port);