11
11
*
12
12
*
13
13
* IDENTIFICATION
14
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.98 2007/10/03 13:57:52 mha Exp $
14
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.99 2007/10/03 15:12:45 tgl Exp $
15
15
*
16
16
* NOTES
17
17
* [ Most of these notes are wrong/obsolete, but perhaps not all ]
@@ -588,8 +588,8 @@ client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey)
588
588
589
589
#ifndef WIN32
590
590
struct stat buf2 ;
591
- #endif
592
591
FILE * fp ;
592
+ #endif
593
593
char fnbuf [MAXPGPATH ];
594
594
BIO * bio ;
595
595
PGconn * conn = (PGconn * ) SSL_get_app_data (ssl );
@@ -602,27 +602,32 @@ client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey)
602
602
return 0 ;
603
603
}
604
604
605
- /* save OpenSSL error stack */
606
- ERR_set_mark ();
607
-
608
605
/* read the user certificate */
609
606
snprintf (fnbuf , sizeof (fnbuf ), "%s/%s" , homedir , USER_CERT_FILE );
610
607
611
608
/*
612
- * OpenSSL <= 0.8.2 lacks error stack handling. Do a separate check
613
- * for the existance of the file without using BIO functions to make
614
- * it pick up the majority of the cases with the old versions.
609
+ * OpenSSL <= 0.9.8 lacks error stack handling, which means it's likely
610
+ * to report wrong error messages if access to the cert file fails.
611
+ * Do our own check for the readability of the file to catch the
612
+ * majority of such problems before OpenSSL gets involved.
615
613
*/
616
614
#ifndef HAVE_ERR_SET_MARK
617
- if ((fp = fopen (fnbuf , "r" )) == NULL )
618
615
{
619
- printfPQExpBuffer (& conn -> errorMessage ,
620
- libpq_gettext ("could not open certificate file \"%s\": %s\n" ),
621
- fnbuf , pqStrerror (errno , sebuf , sizeof (sebuf )));
622
- return 0 ;
616
+ FILE * fp2 ;
617
+
618
+ if ((fp2 = fopen (fnbuf , "r" )) == NULL )
619
+ {
620
+ printfPQExpBuffer (& conn -> errorMessage ,
621
+ libpq_gettext ("could not open certificate file \"%s\": %s\n" ),
622
+ fnbuf , pqStrerror (errno , sebuf , sizeof (sebuf )));
623
+ return 0 ;
624
+ }
625
+ fclose (fp2 );
623
626
}
624
- fclose (fp );
625
627
#endif
628
+
629
+ /* save OpenSSL error stack */
630
+ ERR_set_mark ();
626
631
627
632
if ((bio = BIO_new_file (fnbuf , "r" )) == NULL )
628
633
{
0 commit comments