From ffcdb0e6efb6fb7033b2cd29e8cca2e2fe355c14 Mon Sep 17 00:00:00 2001
From: Matt Caswell <matt@openssl.org>
Date: Tue, 21 Mar 2017 09:07:17 +0000
Subject: [PATCH] Fix error paths in ASN1_TIME_to_generalizedtime

We should not write to |out| in error cases, so we should defer doing this
until the "done" block.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3002)
---
 crypto/asn1/a_time.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/crypto/asn1/a_time.c b/crypto/asn1/a_time.c
index 6074325816..0eeb79cd42 100644
--- a/crypto/asn1/a_time.c
+++ b/crypto/asn1/a_time.c
@@ -147,10 +147,9 @@ ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t,
     if (!out || !*out) {
         if (!(ret = ASN1_GENERALIZEDTIME_new()))
             goto err;
-        if (out)
-            *out = ret;
-    } else
+    } else {
         ret = *out;
+    }
 
     /* If already GeneralizedTime just copy across */
     if (t->type == V_ASN1_GENERALIZEDTIME) {
-- 
2.25.1