diff libpurple/plugins/ssl/ssl-gnutls.c @ 20703:60ba0f4d86a5

- Apply pidgin-old-gnutls-bugfixes.patch from #3192 with slight modification. This compensates for an off-by-one error in old versions of GnuTLS. Thanks to Elliott Sales de Andrade.
author William Ehlhardt <williamehlhardt@gmail.com>
date Sat, 29 Sep 2007 04:01:14 +0000
parents 4711727df736
children f0a44de156fc
line wrap: on
line diff
--- a/libpurple/plugins/ssl/ssl-gnutls.c	Sat Sep 29 03:44:34 2007 +0000
+++ b/libpurple/plugins/ssl/ssl-gnutls.c	Sat Sep 29 04:01:14 2007 +0000
@@ -769,7 +769,10 @@
 	gnutls_x509_crt_get_dn(cert_dat, dn, &dn_size);
 
 	/* Now allocate and get the Distinguished Name */
-	dn = g_new0(gchar, dn_size);
+	/* Old versions of GnuTLS have an off-by-one error in reporting
+	   the size of the needed buffer in some functions, so allocate
+	   an extra byte */
+	dn = g_new0(gchar, ++dn_size);
 	if (0 != gnutls_x509_crt_get_dn(cert_dat, dn, &dn_size)) {
 		purple_debug_error("gnutls/x509",
 				   "Failed to get Distinguished Name\n");
@@ -799,7 +802,10 @@
 	gnutls_x509_crt_get_issuer_dn(cert_dat, dn, &dn_size);
 
 	/* Now allocate and get the Distinguished Name */
-	dn = g_new0(gchar, dn_size);
+	/* Old versions of GnuTLS have an off-by-one error in reporting
+	   the size of the needed buffer in some functions, so allocate
+	   an extra byte */
+	dn = g_new0(gchar, ++dn_size);
 	if (0 != gnutls_x509_crt_get_issuer_dn(cert_dat, dn, &dn_size)) {
 		purple_debug_error("gnutls/x509",
 				   "Failed to get issuer's Distinguished "
@@ -835,7 +841,10 @@
 				      cn, &cn_size);
 
 	/* Now allocate and get the Common Name */
-	cn = g_new0(gchar, cn_size);
+	/* Old versions of GnuTLS have an off-by-one error in reporting
+	   the size of the needed buffer in some functions, so allocate
+	   an extra byte */
+	cn = g_new0(gchar, ++cn_size);
 	ret = gnutls_x509_crt_get_dn_by_oid(cert_dat,
 					    GNUTLS_OID_X520_COMMON_NAME,
 					    0, /* First CN found, please */