summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2021-05-01 13:16:30 +0000
committertb <>2021-05-01 13:16:30 +0000
commitfae403f23baa4e1b63122662c3ebdf9a99097ae3 (patch)
tree855d3e18bd8860d929742fdee066dd3f36a832d7 /src/lib
parentbda487a9531b508fcb2602e5fddbef19d89ff384 (diff)
downloadopenbsd-fae403f23baa4e1b63122662c3ebdf9a99097ae3.tar.gz
openbsd-fae403f23baa4e1b63122662c3ebdf9a99097ae3.tar.bz2
openbsd-fae403f23baa4e1b63122662c3ebdf9a99097ae3.zip
Plug leak in c2i_ASN1_OBJECT
When using the object reuse facility of c2i_ASN1_OBJECT, the dynamically allocated strings a may contain are set to NULL, so we must free them beforehand. Also clear the flag, because that's what OpenSSL chose to do. From Richard Levitte OpenSSL 1.1.1 65b88a75921533ada8b465bc8d5c0817ad927947 ok inoguchi
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/asn1/a_object.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c
index 16c3a1c0fd..8600f80474 100644
--- a/src/lib/libcrypto/asn1/a_object.c
+++ b/src/lib/libcrypto/asn1/a_object.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_object.c,v 1.31 2018/04/25 11:48:21 tb Exp $ */ 1/* $OpenBSD: a_object.c,v 1.32 2021/05/01 13:16:30 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -304,8 +304,6 @@ c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long len)
304 } 304 }
305 } 305 }
306 306
307 /* only the ASN1_OBJECTs from the 'table' will have values
308 * for ->sn or ->ln */
309 if ((a == NULL) || ((*a) == NULL) || 307 if ((a == NULL) || ((*a) == NULL) ||
310 !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) { 308 !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) {
311 if ((ret = ASN1_OBJECT_new()) == NULL) 309 if ((ret = ASN1_OBJECT_new()) == NULL)
@@ -327,6 +325,13 @@ c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long len)
327 325
328 memcpy(data, p, length); 326 memcpy(data, p, length);
329 327
328 /* If there are dynamic strings, free them here, and clear the flag. */
329 if ((ret->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) != 0) {
330 free((void *)ret->sn);
331 free((void *)ret->ln);
332 ret->flags &= ~ASN1_OBJECT_FLAG_DYNAMIC_STRINGS;
333 }
334
330 /* reattach data to object, after which it remains const */ 335 /* reattach data to object, after which it remains const */
331 ret->data = data; 336 ret->data = data;
332 ret->length = length; 337 ret->length = length;