`realhost', passed back from all the backend init functions, was
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Wed, 9 May 2001 14:01:15 +0000 (14:01 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Wed, 9 May 2001 14:01:15 +0000 (14:01 +0000)
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
raw.c
rlogin.c
scp.c
ssh.c
telnet.c
window.c
winnet.c

diff --git a/plink.c b/plink.c
index c9188c1..a72a69b 100644 (file)
--- 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 6106176..04686f3 100644 (file)
--- 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)
 {
index 688c159..15448fc 100644 (file)
--- 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 f414eb8..9a2624a 100644 (file)
--- 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 9f0fe61..e120c15 100644 (file)
--- 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
 
     /*
index 3cef9c7..41de319 100644 (file)
--- 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)
 {
index 5159d09..e89a309 100644 (file)
--- 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);
     }
index 238730c..3c828ad 100644 (file)
--- 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;
 }