From 6e1ebb76bc65c074b780b303a1f1550f5ae4dd3c Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 9 May 2001 14:01:15 +0000 Subject: [PATCH] `realhost', passed back from all the backend init functions, was scoped within those functions. It's now dynamically allocated. git-svn-id: svn://svn.tartarus.org/sgt/putty@1108 cda61777-01e9-0310-a592-d414129be87e --- plink.c | 1 + raw.c | 3 ++- rlogin.c | 3 ++- scp.c | 1 + ssh.c | 5 +++-- telnet.c | 3 ++- window.c | 1 + winnet.c | 22 ++++++++++------------ 8 files changed, 22 insertions(+), 17 deletions(-) diff --git a/plink.c b/plink.c index c9188c16..a72a69be 100644 --- a/plink.c +++ b/plink.c @@ -550,6 +550,7 @@ int main(int argc, char **argv) fprintf(stderr, "Unable to open connection:\n%s", error); return 1; } + sfree(realhost); } connopen = 1; diff --git a/raw.c b/raw.c index 61061769..04686f34 100644 --- a/raw.c +++ b/raw.c @@ -48,7 +48,8 @@ static int raw_receive(Plug plug, int urgent, char *data, int len) * * Returns an error message, or NULL on success. * - * Also places the canonical host name into `realhost'. + * Also places the canonical host name into `realhost'. It must be + * freed by the caller. */ static char *raw_init(char *host, int port, char **realhost) { diff --git a/rlogin.c b/rlogin.c index 688c1594..15448fc4 100644 --- a/rlogin.c +++ b/rlogin.c @@ -77,7 +77,8 @@ static int rlogin_receive(Plug plug, int urgent, char *data, int len) * * Returns an error message, or NULL on success. * - * Also places the canonical host name into `realhost'. + * Also places the canonical host name into `realhost'. It must be + * freed by the caller. */ static char *rlogin_init(char *host, int port, char **realhost) { diff --git a/scp.c b/scp.c index f414eb8f..9a2624aa 100644 --- a/scp.c +++ b/scp.c @@ -517,6 +517,7 @@ static void do_cmd(char *host, char *user, char *cmd) ssh_scp_init(); if (verbose && realhost != NULL) tell_user(stderr, "Connected to %s\n", realhost); + sfree(realhost); } /* diff --git a/ssh.c b/ssh.c index 9f0fe618..e120c152 100644 --- a/ssh.c +++ b/ssh.c @@ -1505,7 +1505,8 @@ static int ssh_receive(Plug plug, int urgent, char *data, int len) /* * Connect to specified host and port. * Returns an error message, or NULL on success. - * Also places the canonical host name into `realhost'. + * Also places the canonical host name into `realhost'. It must be + * freed by the caller. */ static char *connect_to_host(char *host, int port, char **realhost) { @@ -1545,7 +1546,7 @@ static char *connect_to_host(char *host, int port, char **realhost) return err; #ifdef FWHACK - *realhost = FWhost; + *realhost = strdup(FWhost); #endif /* diff --git a/telnet.c b/telnet.c index 3cef9c76..41de3191 100644 --- a/telnet.c +++ b/telnet.c @@ -587,7 +587,8 @@ static int telnet_receive(Plug plug, int urgent, char *data, int len) * * Returns an error message, or NULL on success. * - * Also places the canonical host name into `realhost'. + * Also places the canonical host name into `realhost'. It must be + * freed by the caller. */ static char *telnet_init(char *host, int port, char **realhost) { diff --git a/window.c b/window.c index 5159d098..e89a3098 100644 --- a/window.c +++ b/window.c @@ -476,6 +476,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) sprintf(msg, "%s - PuTTY", realhost); title = msg; } + sfree(realhost); set_title(title); set_icon(title); } diff --git a/winnet.c b/winnet.c index 238730c4..3c828ad8 100644 --- a/winnet.c +++ b/winnet.c @@ -87,11 +87,6 @@ struct SockAddr_tag { #ifdef IPV6 struct addrinfo *ai; /* Address IPv6 style. */ #endif - /* - * We need to have this lengthy enough to hold *any* hostname - * (including IPv6 reverse...) - */ - char realhost[8192]; }; struct buffer { @@ -213,11 +208,12 @@ SockAddr sk_namelookup(char *host, char **canonicalname) SockAddr ret = smalloc(sizeof(struct SockAddr_tag)); unsigned long a; struct hostent *h = NULL; + char realhost[8192]; /* Clear the structure and default to IPv4. */ memset(ret, 0, sizeof(struct SockAddr_tag)); ret->family = 0; /* We set this one when we have resolved the host. */ - *canonicalname = ret->realhost; /* This makes sure we always have a hostname to return. */ + *realhost = '\0'; if ((a = inet_addr(host)) == (unsigned long) INADDR_NONE) { #ifdef IPV6 @@ -312,10 +308,9 @@ SockAddr sk_namelookup(char *host, char **canonicalname) ((struct sockaddr *) ret->ai->ai_addr, ret->family == AF_INET ? sizeof(SOCKADDR_IN) : - sizeof(SOCKADDR_IN6), ret->realhost, - sizeof(ret->realhost), NULL, 0, 0) != 0) { - strncpy(ret->realhost, host, - sizeof(ret->realhost)); + sizeof(SOCKADDR_IN6), realhost, + sizeof(realhost), NULL, 0, 0) != 0) { + strncpy(realhost, host, sizeof(realhost)); } } } @@ -325,7 +320,7 @@ SockAddr sk_namelookup(char *host, char **canonicalname) { memcpy(&a, h->h_addr, sizeof(a)); /* This way we are always sure the h->h_name is valid :) */ - strncpy(ret->realhost, h->h_name, sizeof(ret->realhost)); + strncpy(realhost, h->h_name, sizeof(realhost)); } } #ifdef IPV6 @@ -337,9 +332,12 @@ SockAddr sk_namelookup(char *host, char **canonicalname) * success return from inet_addr. */ ret->family = AF_INET; - *canonicalname = host; + strncpy(realhost, host, sizeof(realhost)); } ret->address = ntohl(a); + realhost[lenof(realhost)-1] = '\0'; + *canonicalname = smalloc(1+strlen(realhost)); + strcpy(*canonicalname, realhost); return ret; } -- 2.11.0