summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2018-06-01 04:05:29 +0000
committerDamien Miller <djm@mindrot.org>2018-06-01 14:20:12 +1000
commit854ae209f992465a276de0b5f10ef770510c2418 (patch)
tree1c8babe9f7afa665eea8492cc45d231b9d6b43c7
parent3e088aaf236ef35beeef3c9be93fd53700df5861 (diff)
upstream: make ssh_remote_ipaddr() capable of being called after
the ssh->state has been torn down; bz#2773 OpenBSD-Commit-ID: 167f12523613ca3d16d7716a690e7afa307dc7eb
-rw-r--r--packet.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/packet.c b/packet.c
index 08a4d661c..ab9a391b5 100644
--- a/packet.c
+++ b/packet.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: packet.c,v 1.270 2018/05/25 03:20:59 dtucker Exp $ */ 1/* $OpenBSD: packet.c,v 1.271 2018/06/01 04:05:29 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
@@ -418,13 +418,16 @@ ssh_packet_start_discard(struct ssh *ssh, struct sshenc *enc,
418int 418int
419ssh_packet_connection_is_on_socket(struct ssh *ssh) 419ssh_packet_connection_is_on_socket(struct ssh *ssh)
420{ 420{
421 struct session_state *state = ssh->state; 421 struct session_state *state;
422 struct sockaddr_storage from, to; 422 struct sockaddr_storage from, to;
423 socklen_t fromlen, tolen; 423 socklen_t fromlen, tolen;
424 424
425 if (state->connection_in == -1 || state->connection_out == -1) 425 if (ssh == NULL || ssh->state == NULL)
426 return 0; 426 return 0;
427 427
428 state = ssh->state;
429 if (state->connection_in == -1 || state->connection_out == -1)
430 return 0;
428 /* filedescriptors in and out are the same, so it's a socket */ 431 /* filedescriptors in and out are the same, so it's a socket */
429 if (state->connection_in == state->connection_out) 432 if (state->connection_in == state->connection_out)
430 return 1; 433 return 1;
@@ -508,11 +511,12 @@ ssh_packet_get_connection_out(struct ssh *ssh)
508const char * 511const char *
509ssh_remote_ipaddr(struct ssh *ssh) 512ssh_remote_ipaddr(struct ssh *ssh)
510{ 513{
511 const int sock = ssh->state->connection_in; 514 int sock;
512 515
513 /* Check whether we have cached the ipaddr. */ 516 /* Check whether we have cached the ipaddr. */
514 if (ssh->remote_ipaddr == NULL) { 517 if (ssh->remote_ipaddr == NULL) {
515 if (ssh_packet_connection_is_on_socket(ssh)) { 518 if (ssh_packet_connection_is_on_socket(ssh)) {
519 sock = ssh->state->connection_in;
516 ssh->remote_ipaddr = get_peer_ipaddr(sock); 520 ssh->remote_ipaddr = get_peer_ipaddr(sock);
517 ssh->remote_port = get_peer_port(sock); 521 ssh->remote_port = get_peer_port(sock);
518 ssh->local_ipaddr = get_local_ipaddr(sock); 522 ssh->local_ipaddr = get_local_ipaddr(sock);