summaryrefslogtreecommitdiff
path: root/packet.c
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 /packet.c
parent3e088aaf236ef35beeef3c9be93fd53700df5861 (diff)
downloadopenssh-git-854ae209f992465a276de0b5f10ef770510c2418.tar.gz
upstream: make ssh_remote_ipaddr() capable of being called after
the ssh->state has been torn down; bz#2773 OpenBSD-Commit-ID: 167f12523613ca3d16d7716a690e7afa307dc7eb
Diffstat (limited to 'packet.c')
-rw-r--r--packet.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/packet.c b/packet.c
index 08a4d661..ab9a391b 100644
--- a/packet.c
+++ b/packet.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: packet.c,v 1.270 2018/05/25 03:20:59 dtucker Exp $ */
+/* $OpenBSD: packet.c,v 1.271 2018/06/01 04:05:29 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* 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,
int
ssh_packet_connection_is_on_socket(struct ssh *ssh)
{
- struct session_state *state = ssh->state;
+ struct session_state *state;
struct sockaddr_storage from, to;
socklen_t fromlen, tolen;
- if (state->connection_in == -1 || state->connection_out == -1)
+ if (ssh == NULL || ssh->state == NULL)
return 0;
+ state = ssh->state;
+ if (state->connection_in == -1 || state->connection_out == -1)
+ return 0;
/* filedescriptors in and out are the same, so it's a socket */
if (state->connection_in == state->connection_out)
return 1;
@@ -508,11 +511,12 @@ ssh_packet_get_connection_out(struct ssh *ssh)
const char *
ssh_remote_ipaddr(struct ssh *ssh)
{
- const int sock = ssh->state->connection_in;
+ int sock;
/* Check whether we have cached the ipaddr. */
if (ssh->remote_ipaddr == NULL) {
if (ssh_packet_connection_is_on_socket(ssh)) {
+ sock = ssh->state->connection_in;
ssh->remote_ipaddr = get_peer_ipaddr(sock);
ssh->remote_port = get_peer_port(sock);
ssh->local_ipaddr = get_local_ipaddr(sock);