summaryrefslogtreecommitdiff
path: root/channels.c
diff options
context:
space:
mode:
Diffstat (limited to 'channels.c')
-rw-r--r--channels.c137
1 files changed, 66 insertions, 71 deletions
diff --git a/channels.c b/channels.c
index 9cf85a38d..ac675c742 100644
--- a/channels.c
+++ b/channels.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: channels.c,v 1.319 2012/12/02 20:46:11 djm Exp $ */ 1/* $OpenBSD: channels.c,v 1.324 2013/07/12 00:19:58 djm Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -213,6 +213,7 @@ channel_lookup(int id)
213 case SSH_CHANNEL_OPEN: 213 case SSH_CHANNEL_OPEN:
214 case SSH_CHANNEL_INPUT_DRAINING: 214 case SSH_CHANNEL_INPUT_DRAINING:
215 case SSH_CHANNEL_OUTPUT_DRAINING: 215 case SSH_CHANNEL_OUTPUT_DRAINING:
216 case SSH_CHANNEL_ABANDONED:
216 return (c); 217 return (c);
217 } 218 }
218 logit("Non-public channel %d, type %d.", id, c->type); 219 logit("Non-public channel %d, type %d.", id, c->type);
@@ -247,7 +248,10 @@ channel_register_fds(Channel *c, int rfd, int wfd, int efd,
247 248
248 if ((c->isatty = is_tty) != 0) 249 if ((c->isatty = is_tty) != 0)
249 debug2("channel %d: rfd %d isatty", c->self, c->rfd); 250 debug2("channel %d: rfd %d isatty", c->self, c->rfd);
251#ifdef _AIX
252 /* XXX: Later AIX versions can't push as much data to tty */
250 c->wfd_isatty = is_tty || isatty(c->wfd); 253 c->wfd_isatty = is_tty || isatty(c->wfd);
254#endif
251 255
252 /* enable nonblocking mode */ 256 /* enable nonblocking mode */
253 if (nonblock) { 257 if (nonblock) {
@@ -401,7 +405,7 @@ channel_free(Channel *c)
401 405
402 s = channel_open_message(); 406 s = channel_open_message();
403 debug3("channel %d: status: %s", c->self, s); 407 debug3("channel %d: status: %s", c->self, s);
404 xfree(s); 408 free(s);
405 409
406 if (c->sock != -1) 410 if (c->sock != -1)
407 shutdown(c->sock, SHUT_RDWR); 411 shutdown(c->sock, SHUT_RDWR);
@@ -409,29 +413,23 @@ channel_free(Channel *c)
409 buffer_free(&c->input); 413 buffer_free(&c->input);
410 buffer_free(&c->output); 414 buffer_free(&c->output);
411 buffer_free(&c->extended); 415 buffer_free(&c->extended);
412 if (c->remote_name) { 416 free(c->remote_name);
413 xfree(c->remote_name); 417 c->remote_name = NULL;
414 c->remote_name = NULL; 418 free(c->path);
415 } 419 c->path = NULL;
416 if (c->path) { 420 free(c->listening_addr);
417 xfree(c->path); 421 c->listening_addr = NULL;
418 c->path = NULL;
419 }
420 if (c->listening_addr) {
421 xfree(c->listening_addr);
422 c->listening_addr = NULL;
423 }
424 while ((cc = TAILQ_FIRST(&c->status_confirms)) != NULL) { 422 while ((cc = TAILQ_FIRST(&c->status_confirms)) != NULL) {
425 if (cc->abandon_cb != NULL) 423 if (cc->abandon_cb != NULL)
426 cc->abandon_cb(c, cc->ctx); 424 cc->abandon_cb(c, cc->ctx);
427 TAILQ_REMOVE(&c->status_confirms, cc, entry); 425 TAILQ_REMOVE(&c->status_confirms, cc, entry);
428 bzero(cc, sizeof(*cc)); 426 bzero(cc, sizeof(*cc));
429 xfree(cc); 427 free(cc);
430 } 428 }
431 if (c->filter_cleanup != NULL && c->filter_ctx != NULL) 429 if (c->filter_cleanup != NULL && c->filter_ctx != NULL)
432 c->filter_cleanup(c->self, c->filter_ctx); 430 c->filter_cleanup(c->self, c->filter_ctx);
433 channels[c->self] = NULL; 431 channels[c->self] = NULL;
434 xfree(c); 432 free(c);
435} 433}
436 434
437void 435void
@@ -536,6 +534,7 @@ channel_still_open(void)
536 case SSH_CHANNEL_DYNAMIC: 534 case SSH_CHANNEL_DYNAMIC:
537 case SSH_CHANNEL_CONNECTING: 535 case SSH_CHANNEL_CONNECTING:
538 case SSH_CHANNEL_ZOMBIE: 536 case SSH_CHANNEL_ZOMBIE:
537 case SSH_CHANNEL_ABANDONED:
539 continue; 538 continue;
540 case SSH_CHANNEL_LARVAL: 539 case SSH_CHANNEL_LARVAL:
541 if (!compat20) 540 if (!compat20)
@@ -581,6 +580,7 @@ channel_find_open(void)
581 case SSH_CHANNEL_OPENING: 580 case SSH_CHANNEL_OPENING:
582 case SSH_CHANNEL_CONNECTING: 581 case SSH_CHANNEL_CONNECTING:
583 case SSH_CHANNEL_ZOMBIE: 582 case SSH_CHANNEL_ZOMBIE:
583 case SSH_CHANNEL_ABANDONED:
584 continue; 584 continue;
585 case SSH_CHANNEL_LARVAL: 585 case SSH_CHANNEL_LARVAL:
586 case SSH_CHANNEL_AUTH_SOCKET: 586 case SSH_CHANNEL_AUTH_SOCKET:
@@ -628,6 +628,7 @@ channel_open_message(void)
628 case SSH_CHANNEL_CLOSED: 628 case SSH_CHANNEL_CLOSED:
629 case SSH_CHANNEL_AUTH_SOCKET: 629 case SSH_CHANNEL_AUTH_SOCKET:
630 case SSH_CHANNEL_ZOMBIE: 630 case SSH_CHANNEL_ZOMBIE:
631 case SSH_CHANNEL_ABANDONED:
631 case SSH_CHANNEL_MUX_CLIENT: 632 case SSH_CHANNEL_MUX_CLIENT:
632 case SSH_CHANNEL_MUX_LISTENER: 633 case SSH_CHANNEL_MUX_LISTENER:
633 continue; 634 continue;
@@ -1080,10 +1081,8 @@ channel_decode_socks4(Channel *c, fd_set *readset, fd_set *writeset)
1080 strlcpy(username, p, sizeof(username)); 1081 strlcpy(username, p, sizeof(username));
1081 buffer_consume(&c->input, len); 1082 buffer_consume(&c->input, len);
1082 1083
1083 if (c->path != NULL) { 1084 free(c->path);
1084 xfree(c->path); 1085 c->path = NULL;
1085 c->path = NULL;
1086 }
1087 if (need == 1) { /* SOCKS4: one string */ 1086 if (need == 1) { /* SOCKS4: one string */
1088 host = inet_ntoa(s4_req.dest_addr); 1087 host = inet_ntoa(s4_req.dest_addr);
1089 c->path = xstrdup(host); 1088 c->path = xstrdup(host);
@@ -1143,7 +1142,8 @@ channel_decode_socks5(Channel *c, fd_set *readset, fd_set *writeset)
1143 u_int8_t atyp; 1142 u_int8_t atyp;
1144 } s5_req, s5_rsp; 1143 } s5_req, s5_rsp;
1145 u_int16_t dest_port; 1144 u_int16_t dest_port;
1146 u_char *p, dest_addr[255+1], ntop[INET6_ADDRSTRLEN]; 1145 char dest_addr[255+1], ntop[INET6_ADDRSTRLEN];
1146 u_char *p;
1147 u_int have, need, i, found, nmethods, addrlen, af; 1147 u_int have, need, i, found, nmethods, addrlen, af;
1148 1148
1149 debug2("channel %d: decode socks5", c->self); 1149 debug2("channel %d: decode socks5", c->self);
@@ -1213,13 +1213,11 @@ channel_decode_socks5(Channel *c, fd_set *readset, fd_set *writeset)
1213 buffer_consume(&c->input, sizeof(s5_req)); 1213 buffer_consume(&c->input, sizeof(s5_req));
1214 if (s5_req.atyp == SSH_SOCKS5_DOMAIN) 1214 if (s5_req.atyp == SSH_SOCKS5_DOMAIN)
1215 buffer_consume(&c->input, 1); /* host string length */ 1215 buffer_consume(&c->input, 1); /* host string length */
1216 buffer_get(&c->input, (char *)&dest_addr, addrlen); 1216 buffer_get(&c->input, &dest_addr, addrlen);
1217 buffer_get(&c->input, (char *)&dest_port, 2); 1217 buffer_get(&c->input, (char *)&dest_port, 2);
1218 dest_addr[addrlen] = '\0'; 1218 dest_addr[addrlen] = '\0';
1219 if (c->path != NULL) { 1219 free(c->path);
1220 xfree(c->path); 1220 c->path = NULL;
1221 c->path = NULL;
1222 }
1223 if (s5_req.atyp == SSH_SOCKS5_DOMAIN) { 1221 if (s5_req.atyp == SSH_SOCKS5_DOMAIN) {
1224 if (addrlen >= NI_MAXHOST) { 1222 if (addrlen >= NI_MAXHOST) {
1225 error("channel %d: dynamic request: socks5 hostname " 1223 error("channel %d: dynamic request: socks5 hostname "
@@ -1241,11 +1239,10 @@ channel_decode_socks5(Channel *c, fd_set *readset, fd_set *writeset)
1241 s5_rsp.command = SSH_SOCKS5_SUCCESS; 1239 s5_rsp.command = SSH_SOCKS5_SUCCESS;
1242 s5_rsp.reserved = 0; /* ignored */ 1240 s5_rsp.reserved = 0; /* ignored */
1243 s5_rsp.atyp = SSH_SOCKS5_IPV4; 1241 s5_rsp.atyp = SSH_SOCKS5_IPV4;
1244 ((struct in_addr *)&dest_addr)->s_addr = INADDR_ANY;
1245 dest_port = 0; /* ignored */ 1242 dest_port = 0; /* ignored */
1246 1243
1247 buffer_append(&c->output, &s5_rsp, sizeof(s5_rsp)); 1244 buffer_append(&c->output, &s5_rsp, sizeof(s5_rsp));
1248 buffer_append(&c->output, &dest_addr, sizeof(struct in_addr)); 1245 buffer_put_int(&c->output, ntohl(INADDR_ANY)); /* bind address */
1249 buffer_append(&c->output, &dest_port, sizeof(dest_port)); 1246 buffer_append(&c->output, &dest_port, sizeof(dest_port));
1250 return 1; 1247 return 1;
1251} 1248}
@@ -1324,7 +1321,7 @@ channel_post_x11_listener(Channel *c, fd_set *readset, fd_set *writeset)
1324{ 1321{
1325 Channel *nc; 1322 Channel *nc;
1326 struct sockaddr_storage addr; 1323 struct sockaddr_storage addr;
1327 int newsock; 1324 int newsock, oerrno;
1328 socklen_t addrlen; 1325 socklen_t addrlen;
1329 char buf[16384], *remote_ipaddr; 1326 char buf[16384], *remote_ipaddr;
1330 int remote_port; 1327 int remote_port;
@@ -1334,14 +1331,18 @@ channel_post_x11_listener(Channel *c, fd_set *readset, fd_set *writeset)
1334 addrlen = sizeof(addr); 1331 addrlen = sizeof(addr);
1335 newsock = accept(c->sock, (struct sockaddr *)&addr, &addrlen); 1332 newsock = accept(c->sock, (struct sockaddr *)&addr, &addrlen);
1336 if (c->single_connection) { 1333 if (c->single_connection) {
1334 oerrno = errno;
1337 debug2("single_connection: closing X11 listener."); 1335 debug2("single_connection: closing X11 listener.");
1338 channel_close_fd(&c->sock); 1336 channel_close_fd(&c->sock);
1339 chan_mark_dead(c); 1337 chan_mark_dead(c);
1338 errno = oerrno;
1340 } 1339 }
1341 if (newsock < 0) { 1340 if (newsock < 0) {
1342 error("accept: %.100s", strerror(errno)); 1341 if (errno != EINTR && errno != EWOULDBLOCK &&
1342 errno != ECONNABORTED)
1343 error("accept: %.100s", strerror(errno));
1343 if (errno == EMFILE || errno == ENFILE) 1344 if (errno == EMFILE || errno == ENFILE)
1344 c->notbefore = time(NULL) + 1; 1345 c->notbefore = monotime() + 1;
1345 return; 1346 return;
1346 } 1347 }
1347 set_nodelay(newsock); 1348 set_nodelay(newsock);
@@ -1375,7 +1376,7 @@ channel_post_x11_listener(Channel *c, fd_set *readset, fd_set *writeset)
1375 packet_put_cstring(buf); 1376 packet_put_cstring(buf);
1376 packet_send(); 1377 packet_send();
1377 } 1378 }
1378 xfree(remote_ipaddr); 1379 free(remote_ipaddr);
1379 } 1380 }
1380} 1381}
1381 1382
@@ -1389,7 +1390,7 @@ port_open_helper(Channel *c, char *rtype)
1389 1390
1390 if (remote_port == -1) { 1391 if (remote_port == -1) {
1391 /* Fake addr/port to appease peers that validate it (Tectia) */ 1392 /* Fake addr/port to appease peers that validate it (Tectia) */
1392 xfree(remote_ipaddr); 1393 free(remote_ipaddr);
1393 remote_ipaddr = xstrdup("127.0.0.1"); 1394 remote_ipaddr = xstrdup("127.0.0.1");
1394 remote_port = 65535; 1395 remote_port = 65535;
1395 } 1396 }
@@ -1402,7 +1403,7 @@ port_open_helper(Channel *c, char *rtype)
1402 rtype, c->listening_port, c->path, c->host_port, 1403 rtype, c->listening_port, c->path, c->host_port,
1403 remote_ipaddr, remote_port); 1404 remote_ipaddr, remote_port);
1404 1405
1405 xfree(c->remote_name); 1406 free(c->remote_name);
1406 c->remote_name = xstrdup(buf); 1407 c->remote_name = xstrdup(buf);
1407 1408
1408 if (compat20) { 1409 if (compat20) {
@@ -1434,7 +1435,7 @@ port_open_helper(Channel *c, char *rtype)
1434 packet_put_cstring(c->remote_name); 1435 packet_put_cstring(c->remote_name);
1435 packet_send(); 1436 packet_send();
1436 } 1437 }
1437 xfree(remote_ipaddr); 1438 free(remote_ipaddr);
1438} 1439}
1439 1440
1440static void 1441static void
@@ -1484,9 +1485,11 @@ channel_post_port_listener(Channel *c, fd_set *readset, fd_set *writeset)
1484 addrlen = sizeof(addr); 1485 addrlen = sizeof(addr);
1485 newsock = accept(c->sock, (struct sockaddr *)&addr, &addrlen); 1486 newsock = accept(c->sock, (struct sockaddr *)&addr, &addrlen);
1486 if (newsock < 0) { 1487 if (newsock < 0) {
1487 error("accept: %.100s", strerror(errno)); 1488 if (errno != EINTR && errno != EWOULDBLOCK &&
1489 errno != ECONNABORTED)
1490 error("accept: %.100s", strerror(errno));
1488 if (errno == EMFILE || errno == ENFILE) 1491 if (errno == EMFILE || errno == ENFILE)
1489 c->notbefore = time(NULL) + 1; 1492 c->notbefore = monotime() + 1;
1490 return; 1493 return;
1491 } 1494 }
1492 set_nodelay(newsock); 1495 set_nodelay(newsock);
@@ -1522,7 +1525,7 @@ channel_post_auth_listener(Channel *c, fd_set *readset, fd_set *writeset)
1522 error("accept from auth socket: %.100s", 1525 error("accept from auth socket: %.100s",
1523 strerror(errno)); 1526 strerror(errno));
1524 if (errno == EMFILE || errno == ENFILE) 1527 if (errno == EMFILE || errno == ENFILE)
1525 c->notbefore = time(NULL) + 1; 1528 c->notbefore = monotime() + 1;
1526 return; 1529 return;
1527 } 1530 }
1528 nc = channel_new("accepted auth socket", 1531 nc = channel_new("accepted auth socket",
@@ -1685,7 +1688,7 @@ channel_handle_wfd(Channel *c, fd_set *readset, fd_set *writeset)
1685 if (c->datagram) { 1688 if (c->datagram) {
1686 /* ignore truncated writes, datagrams might get lost */ 1689 /* ignore truncated writes, datagrams might get lost */
1687 len = write(c->wfd, buf, dlen); 1690 len = write(c->wfd, buf, dlen);
1688 xfree(data); 1691 free(data);
1689 if (len < 0 && (errno == EINTR || errno == EAGAIN || 1692 if (len < 0 && (errno == EINTR || errno == EAGAIN ||
1690 errno == EWOULDBLOCK)) 1693 errno == EWOULDBLOCK))
1691 return 1; 1694 return 1;
@@ -1926,7 +1929,7 @@ channel_post_mux_listener(Channel *c, fd_set *readset, fd_set *writeset)
1926 &addrlen)) == -1) { 1929 &addrlen)) == -1) {
1927 error("%s accept: %s", __func__, strerror(errno)); 1930 error("%s accept: %s", __func__, strerror(errno));
1928 if (errno == EMFILE || errno == ENFILE) 1931 if (errno == EMFILE || errno == ENFILE)
1929 c->notbefore = time(NULL) + 1; 1932 c->notbefore = monotime() + 1;
1930 return; 1933 return;
1931 } 1934 }
1932 1935
@@ -2089,7 +2092,7 @@ channel_handler(chan_fn *ftab[], fd_set *readset, fd_set *writeset,
2089 channel_handler_init(); 2092 channel_handler_init();
2090 did_init = 1; 2093 did_init = 1;
2091 } 2094 }
2092 now = time(NULL); 2095 now = monotime();
2093 if (unpause_secs != NULL) 2096 if (unpause_secs != NULL)
2094 *unpause_secs = 0; 2097 *unpause_secs = 0;
2095 for (i = 0, oalloc = channels_alloc; i < oalloc; i++) { 2098 for (i = 0, oalloc = channels_alloc; i < oalloc; i++) {
@@ -2219,7 +2222,7 @@ channel_output_poll(void)
2219 debug("channel %d: datagram " 2222 debug("channel %d: datagram "
2220 "too big for channel", 2223 "too big for channel",
2221 c->self); 2224 c->self);
2222 xfree(data); 2225 free(data);
2223 continue; 2226 continue;
2224 } 2227 }
2225 packet_start(SSH2_MSG_CHANNEL_DATA); 2228 packet_start(SSH2_MSG_CHANNEL_DATA);
@@ -2227,7 +2230,7 @@ channel_output_poll(void)
2227 packet_put_string(data, dlen); 2230 packet_put_string(data, dlen);
2228 packet_send(); 2231 packet_send();
2229 c->remote_window -= dlen + 4; 2232 c->remote_window -= dlen + 4;
2230 xfree(data); 2233 free(data);
2231 } 2234 }
2232 continue; 2235 continue;
2233 } 2236 }
@@ -2399,13 +2402,13 @@ channel_input_extended_data(int type, u_int32_t seq, void *ctxt)
2399 if (data_len > c->local_window) { 2402 if (data_len > c->local_window) {
2400 logit("channel %d: rcvd too much extended_data %d, win %d", 2403 logit("channel %d: rcvd too much extended_data %d, win %d",
2401 c->self, data_len, c->local_window); 2404 c->self, data_len, c->local_window);
2402 xfree(data); 2405 free(data);
2403 return; 2406 return;
2404 } 2407 }
2405 debug2("channel %d: rcvd ext data %d", c->self, data_len); 2408 debug2("channel %d: rcvd ext data %d", c->self, data_len);
2406 c->local_window -= data_len; 2409 c->local_window -= data_len;
2407 buffer_append(&c->extended, data, data_len); 2410 buffer_append(&c->extended, data, data_len);
2408 xfree(data); 2411 free(data);
2409} 2412}
2410 2413
2411/* ARGSUSED */ 2414/* ARGSUSED */
@@ -2495,7 +2498,7 @@ channel_input_close_confirmation(int type, u_int32_t seq, void *ctxt)
2495 if (c == NULL) 2498 if (c == NULL)
2496 packet_disconnect("Received close confirmation for " 2499 packet_disconnect("Received close confirmation for "
2497 "out-of-range channel %d.", id); 2500 "out-of-range channel %d.", id);
2498 if (c->type != SSH_CHANNEL_CLOSED) 2501 if (c->type != SSH_CHANNEL_CLOSED && c->type != SSH_CHANNEL_ABANDONED)
2499 packet_disconnect("Received close confirmation for " 2502 packet_disconnect("Received close confirmation for "
2500 "non-closed channel %d (type %d).", id, c->type); 2503 "non-closed channel %d (type %d).", id, c->type);
2501 channel_free(c); 2504 channel_free(c);
@@ -2571,10 +2574,8 @@ channel_input_open_failure(int type, u_int32_t seq, void *ctxt)
2571 } 2574 }
2572 logit("channel %d: open failed: %s%s%s", id, 2575 logit("channel %d: open failed: %s%s%s", id,
2573 reason2txt(reason), msg ? ": ": "", msg ? msg : ""); 2576 reason2txt(reason), msg ? ": ": "", msg ? msg : "");
2574 if (msg != NULL) 2577 free(msg);
2575 xfree(msg); 2578 free(lang);
2576 if (lang != NULL)
2577 xfree(lang);
2578 if (c->open_confirm) { 2579 if (c->open_confirm) {
2579 debug2("callback start"); 2580 debug2("callback start");
2580 c->open_confirm(c->self, 0, c->open_confirm_ctx); 2581 c->open_confirm(c->self, 0, c->open_confirm_ctx);
@@ -2632,8 +2633,8 @@ channel_input_port_open(int type, u_int32_t seq, void *ctxt)
2632 packet_check_eom(); 2633 packet_check_eom();
2633 c = channel_connect_to(host, host_port, 2634 c = channel_connect_to(host, host_port,
2634 "connected socket", originator_string); 2635 "connected socket", originator_string);
2635 xfree(originator_string); 2636 free(originator_string);
2636 xfree(host); 2637 free(host);
2637 if (c == NULL) { 2638 if (c == NULL) {
2638 packet_start(SSH_MSG_CHANNEL_OPEN_FAILURE); 2639 packet_start(SSH_MSG_CHANNEL_OPEN_FAILURE);
2639 packet_put_int(remote_id); 2640 packet_put_int(remote_id);
@@ -2668,7 +2669,7 @@ channel_input_status_confirm(int type, u_int32_t seq, void *ctxt)
2668 cc->cb(type, c, cc->ctx); 2669 cc->cb(type, c, cc->ctx);
2669 TAILQ_REMOVE(&c->status_confirms, cc, entry); 2670 TAILQ_REMOVE(&c->status_confirms, cc, entry);
2670 bzero(cc, sizeof(*cc)); 2671 bzero(cc, sizeof(*cc));
2671 xfree(cc); 2672 free(cc);
2672} 2673}
2673 2674
2674/* -- tcp forwarding */ 2675/* -- tcp forwarding */
@@ -3048,7 +3049,7 @@ channel_request_rforward_cancel(const char *host, u_short port)
3048 3049
3049 permitted_opens[i].listen_port = 0; 3050 permitted_opens[i].listen_port = 0;
3050 permitted_opens[i].port_to_connect = 0; 3051 permitted_opens[i].port_to_connect = 0;
3051 xfree(permitted_opens[i].host_to_connect); 3052 free(permitted_opens[i].host_to_connect);
3052 permitted_opens[i].host_to_connect = NULL; 3053 permitted_opens[i].host_to_connect = NULL;
3053 3054
3054 return 0; 3055 return 0;
@@ -3089,7 +3090,7 @@ channel_input_port_forward_request(int is_root, int gateway_ports)
3089 host_port, gateway_ports); 3090 host_port, gateway_ports);
3090 3091
3091 /* Free the argument string. */ 3092 /* Free the argument string. */
3092 xfree(hostname); 3093 free(hostname);
3093 3094
3094 return (success ? 0 : -1); 3095 return (success ? 0 : -1);
3095} 3096}
@@ -3144,7 +3145,7 @@ channel_update_permitted_opens(int idx, int newport)
3144 } else { 3145 } else {
3145 permitted_opens[idx].listen_port = 0; 3146 permitted_opens[idx].listen_port = 0;
3146 permitted_opens[idx].port_to_connect = 0; 3147 permitted_opens[idx].port_to_connect = 0;
3147 xfree(permitted_opens[idx].host_to_connect); 3148 free(permitted_opens[idx].host_to_connect);
3148 permitted_opens[idx].host_to_connect = NULL; 3149 permitted_opens[idx].host_to_connect = NULL;
3149 } 3150 }
3150} 3151}
@@ -3177,12 +3178,9 @@ channel_clear_permitted_opens(void)
3177 int i; 3178 int i;
3178 3179
3179 for (i = 0; i < num_permitted_opens; i++) 3180 for (i = 0; i < num_permitted_opens; i++)
3180 if (permitted_opens[i].host_to_connect != NULL) 3181 free(permitted_opens[i].host_to_connect);
3181 xfree(permitted_opens[i].host_to_connect); 3182 free(permitted_opens);
3182 if (num_permitted_opens > 0) { 3183 permitted_opens = NULL;
3183 xfree(permitted_opens);
3184 permitted_opens = NULL;
3185 }
3186 num_permitted_opens = 0; 3184 num_permitted_opens = 0;
3187} 3185}
3188 3186
@@ -3192,12 +3190,9 @@ channel_clear_adm_permitted_opens(void)
3192 int i; 3190 int i;
3193 3191
3194 for (i = 0; i < num_adm_permitted_opens; i++) 3192 for (i = 0; i < num_adm_permitted_opens; i++)
3195 if (permitted_adm_opens[i].host_to_connect != NULL) 3193 free(permitted_adm_opens[i].host_to_connect);
3196 xfree(permitted_adm_opens[i].host_to_connect); 3194 free(permitted_adm_opens);
3197 if (num_adm_permitted_opens > 0) { 3195 permitted_adm_opens = NULL;
3198 xfree(permitted_adm_opens);
3199 permitted_adm_opens = NULL;
3200 }
3201 num_adm_permitted_opens = 0; 3196 num_adm_permitted_opens = 0;
3202} 3197}
3203 3198
@@ -3291,7 +3286,7 @@ connect_next(struct channel_connect *cctx)
3291static void 3286static void
3292channel_connect_ctx_free(struct channel_connect *cctx) 3287channel_connect_ctx_free(struct channel_connect *cctx)
3293{ 3288{
3294 xfree(cctx->host); 3289 free(cctx->host);
3295 if (cctx->aitop) 3290 if (cctx->aitop)
3296 freeaddrinfo(cctx->aitop); 3291 freeaddrinfo(cctx->aitop);
3297 bzero(cctx, sizeof(*cctx)); 3292 bzero(cctx, sizeof(*cctx));
@@ -3686,7 +3681,7 @@ x11_input_open(int type, u_int32_t seq, void *ctxt)
3686 c->remote_id = remote_id; 3681 c->remote_id = remote_id;
3687 c->force_drain = 1; 3682 c->force_drain = 1;
3688 } 3683 }
3689 xfree(remote_host); 3684 free(remote_host);
3690 if (c == NULL) { 3685 if (c == NULL) {
3691 /* Send refusal to the remote host. */ 3686 /* Send refusal to the remote host. */
3692 packet_start(SSH_MSG_CHANNEL_OPEN_FAILURE); 3687 packet_start(SSH_MSG_CHANNEL_OPEN_FAILURE);
@@ -3794,7 +3789,7 @@ x11_request_forwarding_with_spoofing(int client_session_id, const char *disp,
3794 packet_put_int(screen_number); 3789 packet_put_int(screen_number);
3795 packet_send(); 3790 packet_send();
3796 packet_write_wait(); 3791 packet_write_wait();
3797 xfree(new_data); 3792 free(new_data);
3798} 3793}
3799 3794
3800 3795