summaryrefslogtreecommitdiff
path: root/sshconnect.c
diff options
context:
space:
mode:
Diffstat (limited to 'sshconnect.c')
-rw-r--r--sshconnect.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/sshconnect.c b/sshconnect.c
index a2fbf9e65..87c3770c0 100644
--- a/sshconnect.c
+++ b/sshconnect.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshconnect.c,v 1.244 2014/01/09 23:26:48 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
@@ -1304,7 +1307,7 @@ ssh_put_password(char *password)
1304 padded = xcalloc(1, size); 1307 padded = xcalloc(1, size);
1305 strlcpy(padded, password, size); 1308 strlcpy(padded, password, size);
1306 packet_put_string(padded, size); 1309 packet_put_string(padded, size);
1307 memset(padded, 0, size); 1310 explicit_bzero(padded, size);
1308 free(padded); 1311 free(padded);
1309} 1312}
1310 1313