diff options
author | Richard Levitte <levitte@openssl.org> | 2021-02-23 18:19:38 +0100 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2021-02-24 19:50:10 +0100 |
commit | 6be27456e1346121b1fed797e92353733b59e16e (patch) | |
tree | 36cd44573a17b146c9021cee4afd93bd2dc11738 | |
parent | af8bd1d8359705c6a980c65b0c27c3e90fc43bea (diff) |
Fix string termination and length setting in OSSL_PARAM_BLD_push_utf8_string()
OSSL_PARAM_BLD_push_utf8_string() was still setting the length in
bytes of the UTF8 string to include the terminating NUL byte, while
recent changes excludes that byte from the length. It's still made to
add a NUL byte at the end of the string no matter what.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14035)
-rw-r--r-- | crypto/param_build.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/crypto/param_build.c b/crypto/param_build.c index ce9eaa1fec..954ff81e2a 100644 --- a/crypto/param_build.c +++ b/crypto/param_build.c @@ -74,7 +74,7 @@ static OSSL_PARAM_BLD_DEF *param_push(OSSL_PARAM_BLD *bld, const char *key, pd->key = key; pd->type = type; pd->size = size; - pd->alloc_blocks = bytes_to_blocks(size); + pd->alloc_blocks = bytes_to_blocks(alloc); if ((pd->secure = secure) != 0) bld->secure_blocks += pd->alloc_blocks; else @@ -242,12 +242,12 @@ int OSSL_PARAM_BLD_push_utf8_string(OSSL_PARAM_BLD *bld, const char *key, OSSL_PARAM_BLD_DEF *pd; if (bsize == 0) { - bsize = strlen(buf) + 1; + bsize = strlen(buf); } else if (bsize > INT_MAX) { ERR_raise(ERR_LIB_CRYPTO, CRYPTO_R_STRING_TOO_LONG); return 0; } - pd = param_push(bld, key, bsize, bsize, OSSL_PARAM_UTF8_STRING, 0); + pd = param_push(bld, key, bsize, bsize + 1, OSSL_PARAM_UTF8_STRING, 0); if (pd == NULL) return 0; pd->string = buf; @@ -260,7 +260,7 @@ int OSSL_PARAM_BLD_push_utf8_ptr(OSSL_PARAM_BLD *bld, const char *key, OSSL_PARAM_BLD_DEF *pd; if (bsize == 0) { - bsize = strlen(buf) + 1; + bsize = strlen(buf); } else if (bsize > INT_MAX) { ERR_raise(ERR_LIB_CRYPTO, CRYPTO_R_STRING_TOO_LONG); return 0; @@ -340,6 +340,8 @@ static OSSL_PARAM *param_bld_convert(OSSL_PARAM_BLD *bld, OSSL_PARAM *param, memcpy(p, pd->string, pd->size); else memset(p, 0, pd->size); + if (pd->type == OSSL_PARAM_UTF8_STRING) + ((char *)p)[pd->size] = '\0'; } else { /* Number, but could also be a NULL BIGNUM */ if (pd->size > sizeof(pd->num)) |