From: tb Date: Thu, 3 Mar 2022 11:29:05 +0000 (+0000) Subject: Pull a len == 0 check up before malloc(len) to avoid implementation X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=4f660ce0841403d10fc6e1b016480f5e9f5f1f5f;p=openbsd Pull a len == 0 check up before malloc(len) to avoid implementation defined behavior. ok deraadt inoguchi --- diff --git a/lib/libcrypto/x509/x509_constraints.c b/lib/libcrypto/x509/x509_constraints.c index 5320583137e..c7adaa4b368 100644 --- a/lib/libcrypto/x509/x509_constraints.c +++ b/lib/libcrypto/x509/x509_constraints.c @@ -1,4 +1,4 @@ -/* $OpenBSD: x509_constraints.c,v 1.20 2022/03/02 17:53:03 tb Exp $ */ +/* $OpenBSD: x509_constraints.c,v 1.21 2022/03/03 11:29:05 tb Exp $ */ /* * Copyright (c) 2020 Bob Beck * @@ -747,15 +747,15 @@ x509_constraints_extract_names(struct x509_constraints_names *names, vname->type = GEN_URI; break; case GEN_DIRNAME: + if (len == 0) { + *error = X509_V_ERR_UNSUPPORTED_NAME_SYNTAX; + goto err; + } if (bytes == NULL || ((vname->der = malloc(len)) == NULL)) { *error = X509_V_ERR_OUT_OF_MEM; goto err; } - if (len == 0) { - *error = X509_V_ERR_UNSUPPORTED_NAME_SYNTAX; - goto err; - } memcpy(vname->der, bytes, len); vname->der_len = len; vname->type = GEN_DIRNAME;