Anonymous avatar Anonymous committed 9da7e1f

openssl: Avoid cutting off OpenSSL errors at 119 chars.

ERR_error_string() is just broken, as it returns at most 119 chars
which means error messages are frequently truncated.
Allow for 511 chars using ERR_error_string_n().

Comments (0)

Files changed (1)

libratbox/src/openssl.c

 	return 1;
 }
 
+static const char *
+get_ssl_error(unsigned long err)
+{
+	static char buf[512];
+
+	ERR_error_string_n(err, buf, sizeof buf);
+	return buf;
+}
+
 int
 rb_init_ssl(void)
 {
 	if(ssl_server_ctx == NULL)
 	{
 		rb_lib_log("rb_init_openssl: Unable to initialize OpenSSL server context: %s",
-			   ERR_error_string(ERR_get_error(), NULL));
+			   get_ssl_error(ERR_get_error()));
 		ret = 0;
 	}
 	/* Disable SSLv2, make the client use our settings */
 	if(ssl_client_ctx == NULL)
 	{
 		rb_lib_log("rb_init_openssl: Unable to initialize OpenSSL client context: %s",
-			   ERR_error_string(ERR_get_error(), NULL));
+			   get_ssl_error(ERR_get_error()));
 		ret = 0;
 	}
 	return ret;
 	{
 		err = ERR_get_error();
 		rb_lib_log("rb_setup_ssl_server: Error loading certificate file [%s]: %s", cert,
-			   ERR_error_string(err, NULL));
+			   get_ssl_error(err));
 		return 0;
 	}
 
 	{
 		err = ERR_get_error();
 		rb_lib_log("rb_setup_ssl_server: Error loading keyfile [%s]: %s", keyfile,
-			   ERR_error_string(err, NULL));
+			   get_ssl_error(err));
 		return 0;
 	}
 
 				err = ERR_get_error();
 				rb_lib_log
 					("rb_setup_ssl_server: Error loading DH params file [%s]: %s",
-					 dhfile, ERR_error_string(err, NULL));
+					 dhfile, get_ssl_error(err));
 				BIO_free(bio);
 				return 0;
 			}
 		{
 			err = ERR_get_error();
 			rb_lib_log("rb_setup_ssl_server: Error loading DH params file [%s]: %s",
-				   dhfile, ERR_error_string(err, NULL));
+				   dhfile, get_ssl_error(err));
 		}
 	}
 	return 1;
 const char *
 rb_get_ssl_strerror(rb_fde_t *F)
 {
-	return ERR_error_string(F->ssl_errno, NULL);
+	return get_ssl_error(F->ssl_errno);
 }
 
 int
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.