Private key files closed twice --

Paul Townsend aab at aab.cc.purdue.edu
Wed Feb 21 12:16:19 EST 2001


=====
I believe that each private key file read is closed twice as

    load_private_key(filename, ...)
	fd = open(filename, ...)
	...
	load_private_key_rsa1(fd, ...)
	...
	load_private_key_ssh2(fd, ...)
	...
	close(fd);

Unfortunately, "load_private_key_rsa1" and "load_private_key_ssh2" also
close the file.  It would simplest to remove the `close()'s in the rsa2
and ssh2 routines except that the ssh2 routine converts the file
descriptor into a streams pointer.  The following patch continues to
allow the two routines to do their own closing but moves the `close(fd)'
in "load_private_key" into the default position only.

--    Paul Townsend (aab at purdue.edu)

=-=-=-=-=-=
--- authfile.c.orig	Thu Feb  8 21:11:24 2001
+++ authfile.c	Tue Feb 20 19:27:20 2001
@@ -446,6 +446,7 @@
 	fp = fdopen(fd, "r");
 	if (fp == NULL) {
 		error("fdopen failed");
+		close(fd);
 		return 0;
 	}
 	pk = PEM_read_PrivateKey(fp, NULL, NULL, (char *)passphrase);
@@ -536,10 +537,11 @@
 	case KEY_RSA:
 	case KEY_UNSPEC:
 		ret = load_private_key_ssh2(fd, passphrase, key, comment_return);
+		break;
 	default:
+		close(fd);
 		break;
 	}
-	close(fd);
 	return ret;
 }
 





More information about the openssh-unix-dev mailing list