[dovecot-cvs] dovecot/src/master ssl-init-openssl.c,1.7,1.8

cras at dovecot.org cras at dovecot.org
Wed May 31 16:59:05 EEST 2006


Update of /var/lib/cvs/dovecot/src/master
In directory talvi:/tmp/cvs-serv27544

Modified Files:
	ssl-init-openssl.c 
Log Message:
Reversed last change. Instead handle DH_generate_parameters() call's failure.



Index: ssl-init-openssl.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/master/ssl-init-openssl.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- ssl-init-openssl.c	31 May 2006 13:54:21 -0000	1.7
+++ ssl-init-openssl.c	31 May 2006 13:59:03 -0000	1.8
@@ -17,21 +17,36 @@
 #define DH_PARAM_BITSIZE_COUNT \
         (sizeof(dh_param_bitsizes)/sizeof(dh_param_bitsizes[0]))
 
+static const char *ssl_last_error(void)
+{
+	unsigned long err;
+	char *buf;
+	size_t err_size = 256;
+
+	err = ERR_get_error();
+	if (err == 0)
+		return strerror(errno);
+
+	buf = t_malloc(err_size);
+	buf[err_size-1] = '\0';
+	ERR_error_string_n(err, buf, err_size-1);
+	return buf;
+}
+
 static void generate_dh_parameters(int bitsize, int fd, const char *fname)
 {
         DH *dh = DH_generate_parameters(bitsize, DH_GENERATOR, NULL, NULL);
 	unsigned char *buf, *p;
 	int len;
 
+	if (dh == NULL) {
+		i_fatal("DH_generate_parameters(bits=%d, gen=%d) failed: %s",
+			bitsize, DH_GENERATOR, ssl_last_error());
+	}
+
 	len = i2d_DHparams(dh, NULL);
 	if (len < 0)
-		i_fatal("i2d_DHparams() failed: %lu", ERR_get_error());
-
-	if (len == 0) {
-		i_fatal("i2d_DHparams() returned 0 for data from "
-			"DH_generate_parameters(bits=%d, generator=%d)",
-			bitsize, DH_GENERATOR);
-	}
+		i_fatal("i2d_DHparams() failed: %s", ssl_last_error());
 
 	buf = p = i_malloc(len);
 	len = i2d_DHparams(dh, &p);



More information about the dovecot-cvs mailing list