From 0e3ac6b20a667c2b7d7e6a7d66193799f5fafd11 Mon Sep 17 00:00:00 2001 From: jsing Date: Thu, 22 Oct 2015 15:03:19 +0000 Subject: [PATCH] Restore previous behaviour and allow ASN1_{GENERALIZED,UTC,}TIME_set_string() to be called with a NULL pointer. Found the hard way by @kinichiro on github. ok beck@ --- lib/libcrypto/asn1/a_time_tm.c | 9 +++++++-- lib/libssl/src/crypto/asn1/a_time_tm.c | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/libcrypto/asn1/a_time_tm.c b/lib/libcrypto/asn1/a_time_tm.c index 352b9159ee2..e5ef007bb9e 100644 --- a/lib/libcrypto/asn1/a_time_tm.c +++ b/lib/libcrypto/asn1/a_time_tm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: a_time_tm.c,v 1.6 2015/10/19 16:32:37 beck Exp $ */ +/* $OpenBSD: a_time_tm.c,v 1.7 2015/10/22 15:03:19 jsing Exp $ */ /* * Copyright (c) 2015 Bob Beck * @@ -216,17 +216,22 @@ ASN1_TIME_set_string_internal(ASN1_TIME *s, const char *str, int mode) { int type; char *tmp; - + if ((type = asn1_time_parse(str, strlen(str), NULL, mode)) == -1) return (0); if (mode != 0 && mode != type) return (0); + + if (s == NULL) + return (1); + if ((tmp = strdup(str)) == NULL) return (0); free(s->data); s->data = tmp; s->length = strlen(tmp); s->type = type; + return (1); } diff --git a/lib/libssl/src/crypto/asn1/a_time_tm.c b/lib/libssl/src/crypto/asn1/a_time_tm.c index 352b9159ee2..e5ef007bb9e 100644 --- a/lib/libssl/src/crypto/asn1/a_time_tm.c +++ b/lib/libssl/src/crypto/asn1/a_time_tm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: a_time_tm.c,v 1.6 2015/10/19 16:32:37 beck Exp $ */ +/* $OpenBSD: a_time_tm.c,v 1.7 2015/10/22 15:03:19 jsing Exp $ */ /* * Copyright (c) 2015 Bob Beck * @@ -216,17 +216,22 @@ ASN1_TIME_set_string_internal(ASN1_TIME *s, const char *str, int mode) { int type; char *tmp; - + if ((type = asn1_time_parse(str, strlen(str), NULL, mode)) == -1) return (0); if (mode != 0 && mode != type) return (0); + + if (s == NULL) + return (1); + if ((tmp = strdup(str)) == NULL) return (0); free(s->data); s->data = tmp; s->length = strlen(tmp); s->type = type; + return (1); } -- 2.20.1