]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Enhance the error handling in _openssl_get_subject()
authorDavid Sommerseth <davids@redhat.com>
Sat, 4 Feb 2012 13:51:54 +0000 (14:51 +0100)
committerDavid Sommerseth <davids@redhat.com>
Sat, 4 Feb 2012 13:51:54 +0000 (14:51 +0100)
Avoid an extra goto label and make the code a bit simpler.

Signed-off-by: David Sommerseth <davids@redhat.com>
Acked-by: Heiko Hund <heiko.hund@sophos.com>
Acked-by: Adriaan de Jong <dejong@fox-it.com>
ssl_verify_openssl.c

index e3f2d13fd7fe58a73db4f4da895712f91b5d9c6b..b2c01a32e73bef6207fec68d75750308d62bd832 100644 (file)
@@ -249,21 +249,21 @@ x509_free_sha1_hash (unsigned char *hash)
 char *
 _openssl_get_subject (X509 *cert, char *buf, int size)
 {
-  BIO *subject_bio;
+  BIO *subject_bio = NULL;
   BUF_MEM *subject_mem;
   char *subject = buf;
   int maxlen = size;
 
   subject_bio = BIO_new (BIO_s_mem ());
   if (subject_bio == NULL)
-    goto out;
+    goto err;
 
   X509_NAME_print_ex (subject_bio, X509_get_subject_name (cert),
                       0, XN_FLAG_SEP_CPLUS_SPC | XN_FLAG_FN_SN |
                       ASN1_STRFLGS_UTF8_CONVERT | ASN1_STRFLGS_ESC_CTRL);
 
   if (BIO_eof (subject_bio))
-    goto out_free;
+    goto err;
 
   BIO_get_mem_ptr (subject_bio, &subject_mem);
   if (subject == NULL)
@@ -276,9 +276,10 @@ _openssl_get_subject (X509 *cert, char *buf, int size)
   memcpy (subject, subject_mem->data, maxlen);
   subject[maxlen - 1] = '\0';
 
-out_free:
-  BIO_free (subject_bio);
-out:
+err:
+  if (subject_bio)
+    BIO_free (subject_bio);
+
   return subject;
 }