From 2c8a0eaeb07022184dab502043bf911295ddbece Mon Sep 17 00:00:00 2001 From: tb Date: Tue, 15 Aug 2023 17:38:00 +0000 Subject: [PATCH] Avoid undefined behavior with memcmp(NULL, x, 0) in ASN1_STRING_cmp() ok jsing miod --- lib/libcrypto/asn1/a_string.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/libcrypto/asn1/a_string.c b/lib/libcrypto/asn1/a_string.c index bfd2abf2f73..ca03008186d 100644 --- a/lib/libcrypto/asn1/a_string.c +++ b/lib/libcrypto/asn1/a_string.c @@ -1,4 +1,4 @@ -/* $OpenBSD: a_string.c,v 1.14 2023/07/05 21:23:36 beck Exp $ */ +/* $OpenBSD: a_string.c,v 1.15 2023/08/15 17:38:00 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -119,10 +119,12 @@ ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b) return -1; if ((cmp = (a->length - b->length)) != 0) return cmp; - if ((cmp = memcmp(a->data, b->data, a->length)) != 0) - return cmp; + if (a->length != 0) { + if ((cmp = memcmp(a->data, b->data, a->length)) != 0) + return 0; + } - return (a->type - b->type); + return a->type - b->type; } LCRYPTO_ALIAS(ASN1_STRING_cmp); -- 2.20.1