9070b3
diff -up openssh-7.4p1/pam_ssh_agent_auth-0.10.3/iterate_ssh_agent_keys.c.psaa-seteuid openssh-7.4p1/pam_ssh_agent_auth-0.10.3/iterate_ssh_agent_keys.c
9070b3
--- openssh-7.4p1/pam_ssh_agent_auth-0.10.3/iterate_ssh_agent_keys.c.psaa-seteuid	2017-02-07 15:41:53.172334151 +0100
9070b3
+++ openssh-7.4p1/pam_ssh_agent_auth-0.10.3/iterate_ssh_agent_keys.c	2017-02-07 15:41:53.174334149 +0100
9070b3
@@ -238,17 +238,26 @@ ssh_get_authentication_socket_for_uid(ui
9070b3
 	}
9070b3
 
9070b3
 	errno = 0; 
9070b3
-	seteuid(uid); /* To ensure a race condition is not used to circumvent the stat
9070b3
-	             above, we will temporarily drop UID to the caller */
9070b3
-	if (connect(sock, (struct sockaddr *)&sunaddr, sizeof sunaddr) < 0) {
9070b3
+	/* To ensure a race condition is not used to circumvent the stat
9070b3
+	   above, we will temporarily drop UID to the caller */
9070b3
+	if (seteuid(uid) == -1) {
9070b3
 		close(sock);
9070b3
-        if(errno == EACCES)
9070b3
-		fatal("MAJOR SECURITY WARNING: uid %lu made a deliberate and malicious attempt to open an agent socket owned by another user", (unsigned long) uid);
9070b3
+		error("seteuid(%lu) failed with error: %s",
9070b3
+		    (unsigned long) uid, strerror(errno));
9070b3
 		return -1;
9070b3
 	}
9070b3
+	if (connect(sock, (struct sockaddr *)&sunaddr, sizeof sunaddr) < 0) {
9070b3
+		close(sock);
9070b3
+		sock = -1;
9070b3
+		if(errno == EACCES)
9070b3
+			fatal("MAJOR SECURITY WARNING: uid %lu made a deliberate and malicious attempt to open an agent socket owned by another user", (unsigned long) uid);
9070b3
+	}
9070b3
 
9070b3
-	seteuid(0); /* we now continue the regularly scheduled programming */
9070b3
-
9070b3
+	/* we now continue the regularly scheduled programming */
9070b3
+	if (0 != seteuid(0)) {
9070b3
+		fatal("setuid(0) failed with error: %s", strerror(errno));
9070b3
+		return -1;
9070b3
+	}
9070b3
 	return sock;
9070b3
 }
9070b3