Avoid invoking memcpy if size is zero or the supplied buffer is NULL
authorPaul Dreik <github@pauldreik.se>
Fri, 29 Nov 2019 18:23:35 +0000 (19:23 +0100)
committerTomas Mraz <tomas@openssl.org>
Wed, 25 Aug 2021 15:02:37 +0000 (17:02 +0200)
commit0760d132da046063f6ac3c28bd2ee1d8505e6fcd
tree108e4cbf6d695337bcb35a4820356b81b4de937f
parent562d4cd3c35b32f2bc6ac0770b80ce394f8d76a4
Avoid invoking memcpy if size is zero or the supplied buffer is NULL

This allows for passing a NULL pointer with zero max_len.

Invoking memcpy on NULL is undefined behaviour, even if the size is zero.

https://en.cppreference.com/w/c/string/byte/memcpy

The function can now be queried for the necessary buffer length.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/10541)
crypto/asn1/evp_asn1.c