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)
return 1;
}
-/* int max_len: for returned value */
+/* int max_len: for returned value
+ * if passing NULL in data, nothing is copied but the necessary length
+ * for it is returned.
+ */
int ASN1_TYPE_get_octetstring(const ASN1_TYPE *a, unsigned char *data, int max_len)
{
int ret, num;
num = ret;
else
num = max_len;
- memcpy(data, p, num);
+ if (num > 0 && data != NULL)
+ memcpy(data, p, num);
return ret;
}