coverity 1462571 Dereference after null check
[openssl.git] / test / x509_time_test.c
index 8e813cb0f973ef06794cf7ba8f5de0ba35146f32..41a88ec069b1097512ae66105c06fbb775f3c2bc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2017-2020 The OpenSSL Project Authors. All Rights Reserved.
  *
  * Licensed under the Apache License 2.0 (the "License").  You may not use
  * this file except in compliance with the License.  You can obtain a copy
@@ -327,10 +327,11 @@ static int test_X509_cmp_timeframe(void)
     ASN1_TIME *asn1_before = ASN1_TIME_adj(NULL, now, -1, 0);
     ASN1_TIME *asn1_after = ASN1_TIME_adj(NULL, now, 1, 0);
     X509_VERIFY_PARAM *vpm = X509_VERIFY_PARAM_new();
-    int res;
+    int res = 0;
 
-    res = vpm != NULL
-        && test_X509_cmp_timeframe_vpm(NULL, asn1_before, asn1_mid, asn1_after)
+    if (vpm == NULL)
+        goto finish;
+    res = test_X509_cmp_timeframe_vpm(NULL, asn1_before, asn1_mid, asn1_after)
         && test_X509_cmp_timeframe_vpm(vpm, asn1_before, asn1_mid, asn1_after);
 
     X509_VERIFY_PARAM_set_time(vpm, now);
@@ -340,6 +341,7 @@ static int test_X509_cmp_timeframe(void)
         && test_X509_cmp_timeframe_vpm(vpm, asn1_before, asn1_mid, asn1_after);
 
     X509_VERIFY_PARAM_free(vpm);
+finish:
     ASN1_TIME_free(asn1_mid);
     ASN1_TIME_free(asn1_before);
     ASN1_TIME_free(asn1_after);