summaryrefslogtreecommitdiff
path: root/sshconnect.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2014-02-07 09:24:33 +1100
committerDamien Miller <djm@mindrot.org>2014-02-07 09:24:33 +1100
commitd1a7a9c0fd1ac2e3314cceb2891959fd2cd9eabb (patch)
treed7e46ad598b706c213116c44c43c9fe5d6759676 /sshconnect.c
parent6ce35b6cc4ead1bf98abec34cb2e2d6ca0abb15e (diff)
- djm@cvs.openbsd.org 2014/02/06 22:21:01
[sshconnect.c] in ssh_create_socket(), only do the getaddrinfo for BindAddress when BindAddress is actually specified. Fixes regression in 6.5 for UsePrivilegedPort=yes; patch from Corinna Vinschen
Diffstat (limited to 'sshconnect.c')
-rw-r--r--sshconnect.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/sshconnect.c b/sshconnect.c
index 3781eaf3b..573d7a8e8 100644
--- a/sshconnect.c
+++ b/sshconnect.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshconnect.c,v 1.245 2014/02/02 03:44:31 djm Exp $ */ 1/* $OpenBSD: sshconnect.c,v 1.246 2014/02/06 22:21:01 djm Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -269,7 +269,7 @@ static int
269ssh_create_socket(int privileged, struct addrinfo *ai) 269ssh_create_socket(int privileged, struct addrinfo *ai)
270{ 270{
271 int sock, r, gaierr; 271 int sock, r, gaierr;
272 struct addrinfo hints, *res; 272 struct addrinfo hints, *res = NULL;
273 273
274 sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); 274 sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
275 if (sock < 0) { 275 if (sock < 0) {
@@ -282,17 +282,19 @@ ssh_create_socket(int privileged, struct addrinfo *ai)
282 if (options.bind_address == NULL && !privileged) 282 if (options.bind_address == NULL && !privileged)
283 return sock; 283 return sock;
284 284
285 memset(&hints, 0, sizeof(hints)); 285 if (options.bind_address) {
286 hints.ai_family = ai->ai_family; 286 memset(&hints, 0, sizeof(hints));
287 hints.ai_socktype = ai->ai_socktype; 287 hints.ai_family = ai->ai_family;
288 hints.ai_protocol = ai->ai_protocol; 288 hints.ai_socktype = ai->ai_socktype;
289 hints.ai_flags = AI_PASSIVE; 289 hints.ai_protocol = ai->ai_protocol;
290 gaierr = getaddrinfo(options.bind_address, NULL, &hints, &res); 290 hints.ai_flags = AI_PASSIVE;
291 if (gaierr) { 291 gaierr = getaddrinfo(options.bind_address, NULL, &hints, &res);
292 error("getaddrinfo: %s: %s", options.bind_address, 292 if (gaierr) {
293 ssh_gai_strerror(gaierr)); 293 error("getaddrinfo: %s: %s", options.bind_address,
294 close(sock); 294 ssh_gai_strerror(gaierr));
295 return -1; 295 close(sock);
296 return -1;
297 }
296 } 298 }
297 /* 299 /*
298 * If we are running as root and want to connect to a privileged 300 * If we are running as root and want to connect to a privileged
@@ -300,7 +302,7 @@ ssh_create_socket(int privileged, struct addrinfo *ai)
300 */ 302 */
301 if (privileged) { 303 if (privileged) {
302 PRIV_START; 304 PRIV_START;
303 r = bindresvport_sa(sock, res->ai_addr); 305 r = bindresvport_sa(sock, res ? res->ai_addr : NULL);
304 PRIV_END; 306 PRIV_END;
305 if (r < 0) { 307 if (r < 0) {
306 error("bindresvport_sa: af=%d %s", ai->ai_family, 308 error("bindresvport_sa: af=%d %s", ai->ai_family,
@@ -317,7 +319,8 @@ ssh_create_socket(int privileged, struct addrinfo *ai)
317 return -1; 319 return -1;
318 } 320 }
319 } 321 }
320 freeaddrinfo(res); 322 if (res != NULL)
323 freeaddrinfo(res);
321 return sock; 324 return sock;
322} 325}
323 326