Fix invalid policy detection
authorViktor Dukhovni <openssl-users@dukhovni.org>
Fri, 29 Jan 2016 21:38:21 +0000 (16:38 -0500)
committerViktor Dukhovni <openssl-users@dukhovni.org>
Fri, 29 Jan 2016 22:00:40 +0000 (17:00 -0500)
As a side-effect of opaque x509, ex_flags were looked up too early,
before additional policy cache updates.

Reviewed-by: Dr. Stephen Henson <steve@openssl.org>
crypto/x509v3/pcy_tree.c

index 850d48846009684ede72a73094173fb17c04d1fc..cac2d51dc3aeb366e94c5190d396ab2fde4806f9 100644 (file)
@@ -185,14 +185,18 @@ static int tree_init(X509_POLICY_TREE **ptree, STACK_OF(X509) *certs,
     for (i = n - 2; i >= 0; i--) {
         uint32_t ex_flags;
         x = sk_X509_value(certs, i);
-        ex_flags = X509_get_extension_flags(x);
+
+        /*
+         * Note, this modifies x->ex_flags.  If cache NULL something bad
+         * happened: return immediately
+         */
         cache = policy_cache_set(x);
-        /* If cache NULL something bad happened: return immediately */
         if (cache == NULL)
             return 0;
         /*
          * If inconsistent extensions keep a note of it but continue
          */
+        ex_flags = X509_get_extension_flags(x);
         if (ex_flags & EXFLAG_INVALID_POLICY)
             ret = -1;
         /*