From: tb Date: Tue, 15 Aug 2023 17:38:00 +0000 (+0000) Subject: Avoid undefined behavior with memcmp(NULL, x, 0) in ASN1_STRING_cmp() X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=2c8a0eaeb07022184dab502043bf911295ddbece;p=openbsd Avoid undefined behavior with memcmp(NULL, x, 0) in ASN1_STRING_cmp() ok jsing miod --- 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);