summaryrefslogtreecommitdiff
blob: f5a96f7ad34b2f4b263906f9f080fd11c6c1b4c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
From 35d4608d0e044df48ee8cea13d3cbeafbb33535d Mon Sep 17 00:00:00 2001
From: Martin Johansson <martin@fatbob.nu>
Date: Wed, 29 Aug 2012 21:37:25 +0200
Subject: [PATCH] Fix handling of long cipherstrings/lists with OpenSSL

---
 src/ssl.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/ssl.c b/src/ssl.c
index 0c70427..2204a3c 100644
--- a/src/ssl.c
+++ b/src/ssl.c
@@ -508,10 +508,10 @@ void SSLi_init(void)
 {
 	const SSL_METHOD *method;
 	SSL *ssl;
-	int i, offset = 0;
+	int i, offset = 0, cipherstringlen = 0;
 	STACK_OF(SSL_CIPHER) *cipherlist = NULL, *cipherlist_new = NULL;
 	SSL_CIPHER *cipher;
-	char cipherstring[1024];
+	char *cipherstring, tempstring[128];
 		
 	SSL_library_init();
     OpenSSL_add_all_algorithms();		/* load & register all cryptos, etc. */
@@ -544,11 +544,16 @@ void SSLi_init(void)
 	}
 	Log_debug("List of ciphers:");
 	if (cipherlist_new) {
-		for ( i = 0; (cipher = sk_SSL_CIPHER_value(cipherlist_new, i)) != NULL; i++) {
+		for (i = 0; (cipher = sk_SSL_CIPHER_value(cipherlist_new, i)) != NULL; i++) {
 			Log_debug("%s", SSL_CIPHER_get_name(cipher));
-			offset += snprintf(cipherstring + offset, 1024 - offset, "%s:", SSL_CIPHER_get_name(cipher));
+			cipherstringlen += strlen(SSL_CIPHER_get_name(cipher)) + 1;
+		}
+		cipherstring = malloc(cipherstringlen + 1);
+		if (cipherstring == NULL)
+			Log_fatal("Out of memory");
+		for (i = 0; (cipher = sk_SSL_CIPHER_value(cipherlist_new, i)) != NULL; i++) {
+			offset += sprintf(cipherstring + offset, "%s:", SSL_CIPHER_get_name(cipher));
 		}
-		cipherstring[offset - 1] = '\0';
 	}
 	
 	if (cipherlist_new)
@@ -559,6 +564,8 @@ void SSLi_init(void)
 	
 	if (SSL_CTX_set_cipher_list(context, cipherstring) == 0)
 		Log_fatal("Failed to set cipher list!");
+
+	free(cipherstring);
 	
 	SSL_CTX_set_verify(context, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
 	                   verify_callback);		
-- 
1.8.1.5