Bugzilla – Attachment 1820 Details for
Bug 1742
sshconnect should use port returned by getaddrinfo
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
use getaddrinfo for sshd port lookup
openssh-5.4p1-getaddrinfo.patch (text/plain), 2.15 KB, created by
Jim Rees
on 2010-03-25 06:29:03 AEDT
(
hide
)
Description:
use getaddrinfo for sshd port lookup
Filename:
MIME Type:
Creator:
Jim Rees
Created:
2010-03-25 06:29:03 AEDT
Size:
2.15 KB
patch
obsolete
>diff -ur openssh-5.4p1/ssh.c openssh-5.4p1-pearp/ssh.c >--- openssh-5.4p1/ssh.c 2010-03-12 14:34:40.000000000 -0500 >+++ openssh-5.4p1-pearp/ssh.c 2010-03-12 14:29:46.000000000 -0500 >@@ -671,10 +671,14 @@ > options.user = xstrdup(pw->pw_name); > > /* Get default port if port has not been set. */ >+ /* >+ * This is probably the wrong place to set the default port anyway. >+ * It should be done inside ssh_connect. > if (options.port == 0) { > sp = getservbyname(SSH_SERVICE_NAME, "tcp"); > options.port = sp ? ntohs(sp->s_port) : SSH_DEFAULT_PORT; > } >+ */ > > if (options.local_command != NULL) { > char thishost[NI_MAXHOST]; >diff -ur openssh-5.4p1/sshconnect.c openssh-5.4p1-pearp/sshconnect.c >--- openssh-5.4p1/sshconnect.c 2010-03-12 14:34:45.000000000 -0500 >+++ openssh-5.4p1-pearp/sshconnect.c 2010-03-12 14:29:46.000000000 -0500 >@@ -328,6 +328,7 @@ > int on = 1; > int sock = -1, attempt; > char ntop[NI_MAXHOST], strport[NI_MAXSERV]; >+ char *service = "ssh"; > struct addrinfo hints, *ai, *aitop; > > debug2("ssh_connect: needpriv %d", needpriv); >@@ -342,7 +343,10 @@ > hints.ai_family = family; > hints.ai_socktype = SOCK_STREAM; > snprintf(strport, sizeof strport, "%u", port); >- if ((gaierr = getaddrinfo(host, strport, &hints, &aitop)) != 0) >+ if (port != 0) >+ service = strport; >+ >+ if ((gaierr = getaddrinfo(host, service, &hints, &aitop)) != 0) > fatal("%s: Could not resolve hostname %.100s: %s", __progname, > host, ssh_gai_strerror(gaierr)); > >@@ -357,6 +361,10 @@ > * sequence until the connection succeeds. > */ > for (ai = aitop; ai; ai = ai->ai_next) { >+ struct sockaddr_in *sa = (struct sockaddr_in *) ai->ai_addr; >+ port = ntohs(sa->sin_port); >+ snprintf(strport, sizeof strport, "%u", port); >+ > if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6) > continue; > if (getnameinfo(ai->ai_addr, ai->ai_addrlen, >@@ -386,8 +394,14 @@ > sock = -1; > } > } >- if (sock != -1) >- break; /* Successful connection. */ >+ /* >+ * Successful connection. Save the port that we connected >+ * on because it may be different from this function's input. >+ */ >+ if (sock != -1) { >+ options.port = port; >+ break; >+ } > } > > freeaddrinfo(aitop);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 1742
: 1820