gnutls-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PEM generated by gnutls_rsa_params_export_pkcs1 and gnutls_dh_params


From: Nikos Mavrogiannopoulos
Subject: Re: PEM generated by gnutls_rsa_params_export_pkcs1 and gnutls_dh_params_import_pkcs3
Date: Mon, 23 Jun 2008 02:24:40 +0300
User-agent: Thunderbird 2.0.0.14 (X11/20080505)

Sam Varshavchik wrote:
> The buffer size return value from gnutls_dh_params_import_pkcs3(), when
> specifying GNUTLS_X509_FMT_PEM, seems to include a trailing \0 byte,
> after "-----END DH PARAMETERS-----<NL>". On the other hand,
> gnutls_rsa_params_export_pkcs1() with GNUTLS_X509_FMT_PEM sets the
> returned buffer size to not include any trailing \0, after "-----END RSA
> PRIVATE KEY-----<NL>".
> 
> That's the behavior I've observed with 2.0.4; and I haven't yet built
> 2.4.0. If that's the case, I'm not really sure if it's a major issue,
> but perhaps this should be noted in the man pages.

Hello,
 This is a bug for sure, thank you for reporting it. Does the attached
patch solve your issue?

regards,
Nikos
diff --git a/lib/gnutls_dh_primes.c b/lib/gnutls_dh_primes.c
index 8abab8f..720d2ee 100644
--- a/lib/gnutls_dh_primes.c
+++ b/lib/gnutls_dh_primes.c
@@ -547,21 +547,19 @@ gnutls_dh_params_export_pkcs3 (gnutls_dh_params_t params,
          return GNUTLS_E_INTERNAL_ERROR;
        }
 
-      if ((unsigned) result + 1 > *params_data_size)
+      if ((unsigned) result > *params_data_size)
        {
          gnutls_assert ();
          gnutls_free (out);
-         *params_data_size = result + 1;
+         *params_data_size = result;
          return GNUTLS_E_SHORT_MEMORY_BUFFER;
        }
 
-      *params_data_size = result;
+      *params_data_size = result - 1;
 
       if (params_data)
-       {
-         memcpy (params_data, out, result);
-         params_data[result] = 0;
-       }
+        memcpy (params_data, out, result);
+
       gnutls_free (out);
 
     }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]