1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-25 01:02:24 +00:00

`realhost', passed back from all the backend init functions, was

scoped within those functions. It's now dynamically allocated.

[originally from svn r1108]
This commit is contained in:
Simon Tatham 2001-05-09 14:01:15 +00:00
parent d1d65fa6d0
commit c2eb57a034
8 changed files with 22 additions and 17 deletions

View File

@ -550,6 +550,7 @@ int main(int argc, char **argv)
fprintf(stderr, "Unable to open connection:\n%s", error); fprintf(stderr, "Unable to open connection:\n%s", error);
return 1; return 1;
} }
sfree(realhost);
} }
connopen = 1; connopen = 1;

3
raw.c
View File

@ -48,7 +48,8 @@ static int raw_receive(Plug plug, int urgent, char *data, int len)
* *
* Returns an error message, or NULL on success. * 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) static char *raw_init(char *host, int port, char **realhost)
{ {

View File

@ -77,7 +77,8 @@ static int rlogin_receive(Plug plug, int urgent, char *data, int len)
* *
* Returns an error message, or NULL on success. * 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) static char *rlogin_init(char *host, int port, char **realhost)
{ {

1
scp.c
View File

@ -517,6 +517,7 @@ static void do_cmd(char *host, char *user, char *cmd)
ssh_scp_init(); ssh_scp_init();
if (verbose && realhost != NULL) if (verbose && realhost != NULL)
tell_user(stderr, "Connected to %s\n", realhost); tell_user(stderr, "Connected to %s\n", realhost);
sfree(realhost);
} }
/* /*

5
ssh.c
View File

@ -1505,7 +1505,8 @@ static int ssh_receive(Plug plug, int urgent, char *data, int len)
/* /*
* Connect to specified host and port. * Connect to specified host and port.
* Returns an error message, or NULL on success. * 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) 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; return err;
#ifdef FWHACK #ifdef FWHACK
*realhost = FWhost; *realhost = strdup(FWhost);
#endif #endif
/* /*

View File

@ -587,7 +587,8 @@ static int telnet_receive(Plug plug, int urgent, char *data, int len)
* *
* Returns an error message, or NULL on success. * 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) static char *telnet_init(char *host, int port, char **realhost)
{ {

View File

@ -476,6 +476,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
sprintf(msg, "%s - PuTTY", realhost); sprintf(msg, "%s - PuTTY", realhost);
title = msg; title = msg;
} }
sfree(realhost);
set_title(title); set_title(title);
set_icon(title); set_icon(title);
} }

View File

@ -87,11 +87,6 @@ struct SockAddr_tag {
#ifdef IPV6 #ifdef IPV6
struct addrinfo *ai; /* Address IPv6 style. */ struct addrinfo *ai; /* Address IPv6 style. */
#endif #endif
/*
* We need to have this lengthy enough to hold *any* hostname
* (including IPv6 reverse...)
*/
char realhost[8192];
}; };
struct buffer { struct buffer {
@ -213,11 +208,12 @@ SockAddr sk_namelookup(char *host, char **canonicalname)
SockAddr ret = smalloc(sizeof(struct SockAddr_tag)); SockAddr ret = smalloc(sizeof(struct SockAddr_tag));
unsigned long a; unsigned long a;
struct hostent *h = NULL; struct hostent *h = NULL;
char realhost[8192];
/* Clear the structure and default to IPv4. */ /* Clear the structure and default to IPv4. */
memset(ret, 0, sizeof(struct SockAddr_tag)); memset(ret, 0, sizeof(struct SockAddr_tag));
ret->family = 0; /* We set this one when we have resolved the host. */ 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) { if ((a = inet_addr(host)) == (unsigned long) INADDR_NONE) {
#ifdef IPV6 #ifdef IPV6
@ -312,10 +308,9 @@ SockAddr sk_namelookup(char *host, char **canonicalname)
((struct sockaddr *) ret->ai->ai_addr, ((struct sockaddr *) ret->ai->ai_addr,
ret->family == ret->family ==
AF_INET ? sizeof(SOCKADDR_IN) : AF_INET ? sizeof(SOCKADDR_IN) :
sizeof(SOCKADDR_IN6), ret->realhost, sizeof(SOCKADDR_IN6), realhost,
sizeof(ret->realhost), NULL, 0, 0) != 0) { sizeof(realhost), NULL, 0, 0) != 0) {
strncpy(ret->realhost, host, strncpy(realhost, host, sizeof(realhost));
sizeof(ret->realhost));
} }
} }
} }
@ -325,7 +320,7 @@ SockAddr sk_namelookup(char *host, char **canonicalname)
{ {
memcpy(&a, h->h_addr, sizeof(a)); memcpy(&a, h->h_addr, sizeof(a));
/* This way we are always sure the h->h_name is valid :) */ /* 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 #ifdef IPV6
@ -337,9 +332,12 @@ SockAddr sk_namelookup(char *host, char **canonicalname)
* success return from inet_addr. * success return from inet_addr.
*/ */
ret->family = AF_INET; ret->family = AF_INET;
*canonicalname = host; strncpy(realhost, host, sizeof(realhost));
} }
ret->address = ntohl(a); ret->address = ntohl(a);
realhost[lenof(realhost)-1] = '\0';
*canonicalname = smalloc(1+strlen(realhost));
strcpy(*canonicalname, realhost);
return ret; return ret;
} }