summaryrefslogtreecommitdiffstats
path: root/providers/implementations/rands/drbg_ctr.c
diff options
context:
space:
mode:
Diffstat (limited to 'providers/implementations/rands/drbg_ctr.c')
-rw-r--r--providers/implementations/rands/drbg_ctr.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/providers/implementations/rands/drbg_ctr.c b/providers/implementations/rands/drbg_ctr.c
index 127d85a2cc..e10b4378b5 100644
--- a/providers/implementations/rands/drbg_ctr.c
+++ b/providers/implementations/rands/drbg_ctr.c
@@ -685,19 +685,21 @@ static int drbg_ctr_set_ctx_params(void *vctx, const OSSL_PARAM params[])
if ((p = OSSL_PARAM_locate_const(params, OSSL_DRBG_PARAM_CIPHER)) != NULL) {
const char *base = (const char *)p->data;
+ size_t ctr_str_len = sizeof("CTR") - 1;
+ size_t ecb_str_len = sizeof("ECB") - 1;
if (p->data_type != OSSL_PARAM_UTF8_STRING
- || p->data_size < 3)
+ || p->data_size < ctr_str_len)
return 0;
- if (strcasecmp("CTR", base + p->data_size - sizeof("CTR")) != 0) {
+ if (strcasecmp("CTR", base + p->data_size - ctr_str_len) != 0) {
ERR_raise(ERR_LIB_PROV, PROV_R_REQUIRE_CTR_MODE_CIPHER);
return 0;
}
- if ((ecb = OPENSSL_strdup(base)) == NULL) {
+ if ((ecb = OPENSSL_strndup(base, p->data_size)) == NULL) {
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
return 0;
}
- strcpy(ecb + p->data_size - sizeof("ECB"), "ECB");
+ strcpy(ecb + p->data_size - ecb_str_len, "ECB");
EVP_CIPHER_free(ctr->cipher_ecb);
EVP_CIPHER_free(ctr->cipher_ctr);
ctr->cipher_ctr = EVP_CIPHER_fetch(libctx, base, propquery);