From 3113932151b7d2358565e41c3f81f230436126c9 Mon Sep 17 00:00:00 2001
From: Matt Johnston <matt@ucc.asn.au>
Date: Sat, 28 Feb 2015 23:49:39 +0800
Subject: [PATCH] Better failure handling

---
 netio.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/netio.c b/netio.c
index 42d1b32d..9c84958a 100644
--- a/netio.c
+++ b/netio.c
@@ -169,11 +169,10 @@ struct dropbear_progress_connection *connect_remote(const char* remotehost, cons
 		snprintf(c->errstring, len, "Error resolving '%s' port '%s'. %s", 
 				remotehost, remoteport, gai_strerror(err));
 		TRACE(("Error resolving: %s", gai_strerror(err)))
-		return NULL;
+	} else {
+		c->res_iter = c->res;
 	}
 
-	c->res_iter = c->res;
-
 	return c;
 }
 
@@ -220,7 +219,7 @@ void handle_connect_fds(fd_set *writefd) {
 		socklen_t vallen = sizeof(val);
 		struct dropbear_progress_connection *c = iter->item;
 
-		if (!FD_ISSET(c->sock, writefd)) {
+		if (c->sock < 0 || !FD_ISSET(c->sock, writefd)) {
 			continue;
 		}
 
-- 
GitLab