diff options
author | Simon Josefsson <simon@josefsson.org> | 2010-07-25 18:27:04 +0200 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2010-07-25 18:27:04 +0200 |
commit | a0c6e34c983423d41c80652402fc2cd17ef27a5c (patch) | |
tree | bc8c80defce8f46c27bb543e30d23157fdec7018 /src/common.c | |
parent | a1474d558e182b1c23320f8e865249fd27d810e7 (diff) | |
download | gnutls-a0c6e34c983423d41c80652402fc2cd17ef27a5c.tar.gz |
Avoid fixed size buffers (now handles the big >100 SAN cert).
Diffstat (limited to 'src/common.c')
-rw-r--r-- | src/common.c | 49 |
1 files changed, 37 insertions, 12 deletions
diff --git a/src/common.c b/src/common.c index 1371ded9e1..7590482d79 100644 --- a/src/common.c +++ b/src/common.c @@ -44,8 +44,6 @@ int print_cert; extern int verbose; -static char buffer[5 * 1024]; - const char str_unknown[] = "(unknown)"; /* Hex encodes the given data. @@ -115,12 +113,23 @@ print_x509_info (gnutls_session_t session, const char *hostname, int insecure) if (print_cert) { - size_t size; - - size = sizeof (buffer); + size_t size = 0; + char *p = NULL; ret = gnutls_x509_crt_export (crt, GNUTLS_X509_FMT_PEM, - buffer, &size); + p, &size); + if (ret == GNUTLS_E_SHORT_MEMORY_BUFFER) + { + p = malloc (size); + if (!p) + { + fprintf (stderr, "gnutls_malloc\n"); + exit (1); + } + + ret = gnutls_x509_crt_export (crt, GNUTLS_X509_FMT_PEM, + p, &size); + } if (ret < 0) { fprintf (stderr, "Encoding error: %s\n", gnutls_strerror (ret)); @@ -128,8 +137,10 @@ print_x509_info (gnutls_session_t session, const char *hostname, int insecure) } fputs ("\n", stdout); - fputs (buffer, stdout); + fputs (p, stdout); fputs ("\n", stdout); + + gnutls_free (p); } if (j == 0 && hostname != NULL) @@ -200,19 +211,33 @@ print_openpgp_info (gnutls_session_t session, const char *hostname, if (print_cert) { - size_t size; - - size = sizeof (buffer); + size_t size = 0; + char *p = NULL; ret = gnutls_openpgp_crt_export (crt, GNUTLS_OPENPGP_FMT_BASE64, - buffer, &size); + p, &size); + if (ret == GNUTLS_E_SHORT_MEMORY_BUFFER) + { + p = malloc (size); + if (!p) + { + fprintf (stderr, "gnutls_malloc\n"); + exit (1); + } + + ret = gnutls_openpgp_crt_export (crt, GNUTLS_OPENPGP_FMT_BASE64, + p, &size); + } if (ret < 0) { fprintf (stderr, "Encoding error: %s\n", gnutls_strerror (ret)); return; } - fputs (buffer, stdout); + + fputs (p, stdout); fputs ("\n", stdout); + + gnutls_free (p); } if (hostname != NULL) |