Check ASN1_INTEGER_get for errors.
[openssl.git] / crypto / asn1 / t_x509.c
index c32f28efee35c5cefe6ff047196e2a20d7cd8f07..12a9ed4940aee69a4e7817c37d4e6a791b6273aa 100644 (file)
@@ -57,7 +57,7 @@
  */
 
 #include <stdio.h>
-#include "cryptlib.h"
+#include "internal/cryptlib.h"
 #include <openssl/buffer.h>
 #include <openssl/bn.h>
 #ifndef OPENSSL_NO_RSA
@@ -141,7 +141,13 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags,
 
         bs = X509_get_serialNumber(x);
         if (bs->length <= (int)sizeof(long)) {
-            l = ASN1_INTEGER_get(bs);
+                ERR_set_mark();
+                l = ASN1_INTEGER_get(bs);
+                ERR_pop_to_mark();
+        } else {
+            l = -1;
+        }
+        if (l != -1) {
             if (bs->type == V_ASN1_NEG_INTEGER) {
                 l = -l;
                 neg = "-";
@@ -490,7 +496,7 @@ int ASN1_UTCTIME_print(BIO *bp, const ASN1_UTCTIME *tm)
 int X509_NAME_print(BIO *bp, X509_NAME *name, int obase)
 {
     char *s, *c, *b;
-    int ret = 0, l, i;
+    int l, i;
 
     l = 80 - 2 - obase;
 
@@ -535,11 +541,10 @@ int X509_NAME_print(BIO *bp, X509_NAME *name, int obase)
         l--;
     }
 
-    ret = 1;
-    if (0) {
+    OPENSSL_free(b);
+    return 1;
  err:
-        X509err(X509_F_X509_NAME_PRINT, ERR_R_BUF_LIB);
-    }
+    X509err(X509_F_X509_NAME_PRINT, ERR_R_BUF_LIB);
     OPENSSL_free(b);
-    return (ret);
+    return 0;
 }