Ensure we use a non-zero time for tickets in early data
[openssl.git] / fuzz / asn1.c
index 449d851e68037870c496352cec72bcceb2f60352..ee602a08a3d91230c05ed32340b074d668f5a13f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-2022 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.
@@ -37,7 +37,7 @@
 #include <openssl/bio.h>
 #include <openssl/evp.h>
 #include <openssl/ssl.h>
-#include <internal/nelem.h>
+#include "internal/nelem.h"
 #include "fuzzer.h"
 
 static ASN1_ITEM_EXP *item_type[] = {
@@ -218,8 +218,10 @@ static ASN1_PCTX *pctx;
         int len2; \
         BIO *bio = BIO_new(BIO_s_null()); \
         \
-        PRINT(bio, type); \
-        BIO_free(bio); \
+        if (bio != NULL) { \
+            PRINT(bio, type); \
+            BIO_free(bio); \
+        } \
         len2 = I2D(type, &der); \
         if (len2 != 0) {} \
         OPENSSL_free(der); \
@@ -235,8 +237,10 @@ static ASN1_PCTX *pctx;
     if (type != NULL) { \
         BIO *bio = BIO_new(BIO_s_null()); \
         \
-        PRINT(bio, type, 0); \
-        BIO_free(bio); \
+        if (bio != NULL) { \
+            PRINT(bio, type, 0); \
+            BIO_free(bio); \
+        } \
         I2D(type, &der); \
         OPENSSL_free(der); \
         TYPE ## _free(type); \
@@ -251,8 +255,10 @@ static ASN1_PCTX *pctx;
     if (type != NULL) { \
         BIO *bio = BIO_new(BIO_s_null()); \
         \
-        PRINT(bio, type, 0, pctx); \
-        BIO_free(bio); \
+        if (bio != NULL) { \
+            PRINT(bio, type, 0, pctx); \
+            BIO_free(bio); \
+        } \
         I2D(type, &der); \
         OPENSSL_free(der); \
         TYPE ## _free(type); \
@@ -307,11 +313,13 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
 
         if (o != NULL) {
             BIO *bio = BIO_new(BIO_s_null());
-
-            ASN1_item_print(bio, o, 4, i, pctx);
-            BIO_free(bio);
-            ASN1_item_i2d(o, &der, i);
-            OPENSSL_free(der);
+            if (bio != NULL) {
+                ASN1_item_print(bio, o, 4, i, pctx);
+                BIO_free(bio);
+            }
+            if (ASN1_item_i2d(o, &der, i) > 0) {
+                OPENSSL_free(der);
+            }
             ASN1_item_free(o, i);
         }
     }