changeset 975:bfc8e66ceacf coverity

merge to coverity
author Matt Johnston <matt@ucc.asn.au>
date Tue, 21 Oct 2014 22:34:20 +0800
parents 763979a9c1f1 (current diff) 7c9377467934 (diff)
children 8d0c33e8ddab
files
diffstat 2 files changed, 25 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/chansession.h	Tue Aug 19 23:36:46 2014 +0800
+++ b/chansession.h	Tue Oct 21 22:34:20 2014 +0800
@@ -51,9 +51,12 @@
 	/* exit details */
 	struct exitinfo exit;
 
-	/* Used to set $SSH_CONNECTION in the child session. 
-	Is only set temporarily before forking */
+
+	/* These are only set temporarily before forking */
+	/* Used to set $SSH_CONNECTION in the child session.  */
 	char *connection_string;
+	/* Used to set $SSH_CLIENT in the child session. */
+	char *client_string;
 	
 #ifndef DISABLE_X11FWD
 	struct Listener * x11listener;
--- a/svr-chansession.c	Tue Aug 19 23:36:46 2014 +0800
+++ b/svr-chansession.c	Tue Oct 21 22:34:20 2014 +0800
@@ -241,6 +241,7 @@
 	chansess = (struct ChanSess*)m_malloc(sizeof(struct ChanSess));
 	chansess->cmd = NULL;
 	chansess->connection_string = NULL;
+	chansess->client_string = NULL;
 	chansess->pid = 0;
 
 	/* pty details */
@@ -602,19 +603,26 @@
 	return DROPBEAR_SUCCESS;
 }
 
-static char* make_connection_string() {
+static void make_connection_string(struct ChanSess *chansess) {
 	char *local_ip, *local_port, *remote_ip, *remote_port;
 	size_t len;
-	char *ret;
 	get_socket_address(ses.sock_in, &local_ip, &local_port, &remote_ip, &remote_port, 0);
-	len = strlen(local_ip) + strlen(local_port) + strlen(remote_ip) + strlen(remote_port) + 4;
-	ret = m_malloc(len);
-	snprintf(ret, len, "%s %s %s %s", remote_ip, remote_port, local_ip, local_port);
+
+	/* "remoteip remoteport localip localport" */
+	len = strlen(local_ip) + strlen(remote_ip) + 20;
+	chansess->connection_string = m_malloc(len);
+	snprintf(chansess->connection_string, len, "%s %s %s %s", remote_ip, remote_port, local_ip, local_port);
+
+	/* deprecated but bash only loads .bashrc if SSH_CLIENT is set */ 
+	/* "remoteip remoteport localport" */
+	len = strlen(remote_ip) + 20;
+	chansess->client_string = m_malloc(len);
+	snprintf(chansess->client_string, len, "%s %s %s", remote_ip, remote_port, local_port);
+
 	m_free(local_ip);
 	m_free(local_port);
 	m_free(remote_ip);
 	m_free(remote_port);
-	return ret;
 }
 
 /* Handle a command request from the client. This is used for both shell
@@ -677,7 +685,7 @@
 	/* uClinux will vfork(), so there'll be a race as 
 	connection_string is freed below. */
 #ifndef USE_VFORK
-	chansess->connection_string = make_connection_string();
+	make_connection_string(chansess);
 #endif
 
 	if (chansess->term == NULL) {
@@ -694,6 +702,7 @@
 
 #ifndef USE_VFORK
 	m_free(chansess->connection_string);
+	m_free(chansess->client_string);
 #endif
 
 	if (ret == DROPBEAR_FAILURE) {
@@ -949,6 +958,10 @@
 	if (chansess->connection_string) {
 		addnewvar("SSH_CONNECTION", chansess->connection_string);
 	}
+
+	if (chansess->client_string) {
+		addnewvar("SSH_CLIENT", chansess->client_string);
+	}
 	
 #ifdef ENABLE_SVR_PUBKEY_OPTIONS
 	if (chansess->original_command) {