Fix potential NULL dereference in OSSL_PARAM_get_utf8_string()

Fixes Coverity ID 1476283

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14928)
This commit is contained in:
Tomas Mraz 2021-04-19 16:02:16 +02:00
parent db6b1266ab
commit 1fac270501
2 changed files with 4 additions and 2 deletions

View File

@ -1128,11 +1128,13 @@ int OSSL_PARAM_get_utf8_string(const OSSL_PARAM *p, char **val, size_t max_len)
*/
size_t data_length = p->data_size;
if (ret == 0)
return 0;
if (data_length >= max_len)
data_length = OPENSSL_strnlen(p->data, data_length);
if (data_length >= max_len)
return 0; /* No space for a terminating NUL byte */
((char *)*val)[data_length] = '\0';
(*val)[data_length] = '\0';
return ret;
}

View File

@ -566,7 +566,7 @@ static int do_check_utf8_str(OSSL_PARAM params[], const char *key,
const char *expected)
{
OSSL_PARAM *p;
char *bufp = 0;
char *bufp = NULL;
int ret;
ret = TEST_ptr(p = OSSL_PARAM_locate(params, key))