summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2024-04-09 13:56:00 +0000
committertb <>2024-04-09 13:56:00 +0000
commita57916bb77bc748d39d546df8b878e9f84fe5de8 (patch)
tree2598f4b5ffa3bba1453768c32952e6b075054d7b /src
parent64a4a93afb604f4128a9e9ef205ceba1a2a1d3f5 (diff)
downloadopenbsd-a57916bb77bc748d39d546df8b878e9f84fe5de8.tar.gz
openbsd-a57916bb77bc748d39d546df8b878e9f84fe5de8.tar.bz2
openbsd-a57916bb77bc748d39d546df8b878e9f84fe5de8.zip
Plug leaks in ASN1_TIME_set_string_internal()
This API can be called with s == NULL, in which case the tm_to_*() functions helpfully allocate a new s and then leak. This is a rather ugly fix to make portable ASAN regress happy again, the better fix will be to rewrite the tm_to_*() functions and adjust their callers. That is more intrusive and will be done in a later pass. ok bcook jsing
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/asn1/a_time_tm.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/lib/libcrypto/asn1/a_time_tm.c b/src/lib/libcrypto/asn1/a_time_tm.c
index c8eabec08f..16b9df2584 100644
--- a/src/lib/libcrypto/asn1/a_time_tm.c
+++ b/src/lib/libcrypto/asn1/a_time_tm.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_time_tm.c,v 1.34 2024/04/08 19:57:40 beck Exp $ */ 1/* $OpenBSD: a_time_tm.c,v 1.35 2024/04/09 13:56:00 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2015 Bob Beck <beck@openbsd.org> 3 * Copyright (c) 2015 Bob Beck <beck@openbsd.org>
4 * 4 *
@@ -344,21 +344,32 @@ ASN1_time_parse(const char *bytes, size_t len, struct tm *tm, int mode)
344static int 344static int
345ASN1_TIME_set_string_internal(ASN1_TIME *s, const char *str, int mode) 345ASN1_TIME_set_string_internal(ASN1_TIME *s, const char *str, int mode)
346{ 346{
347 ASN1_TIME *atime = s;
347 struct tm tm; 348 struct tm tm;
348 int type; 349 int type;
350 int ret = 0;
349 351
350 if ((type = ASN1_time_parse(str, strlen(str), &tm, mode)) == -1) 352 if ((type = ASN1_time_parse(str, strlen(str), &tm, mode)) == -1)
351 return (0); 353 return (0);
352 switch(mode) { 354 switch (mode) {
353 case V_ASN1_UTCTIME: 355 case V_ASN1_UTCTIME:
354 return (type == mode && tm_to_utctime(&tm, s) != NULL); 356 ret = (type == mode && (atime = tm_to_utctime(&tm, s)) != NULL);
357 break;
355 case V_ASN1_GENERALIZEDTIME: 358 case V_ASN1_GENERALIZEDTIME:
356 return (type == mode && tm_to_gentime(&tm, s) != NULL); 359 ret = (type == mode && (atime = tm_to_gentime(&tm, s)) != NULL);
360 break;
357 case RFC5280: 361 case RFC5280:
358 return (tm_to_rfc5280_time(&tm, s) != NULL); 362 ret = ((atime = tm_to_rfc5280_time(&tm, s)) != NULL);
363 break;
359 default: 364 default:
360 return (0); 365 ret = 0;
366 break;
361 } 367 }
368
369 if (atime != s)
370 ASN1_TIME_free(atime);
371
372 return ret;
362} 373}
363 374
364static ASN1_TIME * 375static ASN1_TIME *