diff options
author | Richard Levitte <levitte@openssl.org> | 2019-09-26 07:45:33 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2019-09-27 19:03:34 +0200 |
commit | 8f3b8fd6f45fc5f2ab924011908a1e66c2dba462 (patch) | |
tree | beee6b69801d4025d41225e466e7513a6bc416e8 /crypto/params.c | |
parent | d4d28783473e5b4417068258f2553896ff618600 (diff) |
OSSL_PARAM functions: change to allow the data field to be NULL
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/10025)
Diffstat (limited to 'crypto/params.c')
-rw-r--r-- | crypto/params.c | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/crypto/params.c b/crypto/params.c index 20082ad90b..b2ceb13278 100644 --- a/crypto/params.c +++ b/crypto/params.c @@ -211,6 +211,8 @@ int OSSL_PARAM_set_int32(OSSL_PARAM *p, int32_t val) p->return_size = 0; if (p->data_type == OSSL_PARAM_INTEGER) { p->return_size = sizeof(int32_t); /* Minimum expected size */ + if (p->data == NULL) + return 1; switch (p->data_size) { case sizeof(int32_t): *(int32_t *)p->data = val; @@ -222,6 +224,8 @@ int OSSL_PARAM_set_int32(OSSL_PARAM *p, int32_t val) } } else if (p->data_type == OSSL_PARAM_UNSIGNED_INTEGER && val >= 0) { p->return_size = sizeof(uint32_t); /* Minimum expected size */ + if (p->data == NULL) + return 1; switch (p->data_size) { case sizeof(uint32_t): *(uint32_t *)p->data = (uint32_t)val; @@ -233,6 +237,8 @@ int OSSL_PARAM_set_int32(OSSL_PARAM *p, int32_t val) } } else if (p->data_type == OSSL_PARAM_REAL) { p->return_size = sizeof(double); + if (p->data == NULL) + return 1; switch (p->data_size) { case sizeof(double): *(double *)p->data = (double)val; @@ -310,6 +316,8 @@ int OSSL_PARAM_set_uint32(OSSL_PARAM *p, uint32_t val) if (p->data_type == OSSL_PARAM_UNSIGNED_INTEGER) { p->return_size = sizeof(uint32_t); /* Minimum expected size */ + if (p->data == NULL) + return 1; switch (p->data_size) { case sizeof(uint32_t): *(uint32_t *)p->data = val; @@ -321,6 +329,8 @@ int OSSL_PARAM_set_uint32(OSSL_PARAM *p, uint32_t val) } } else if (p->data_type == OSSL_PARAM_INTEGER) { p->return_size = sizeof(int32_t); /* Minimum expected size */ + if (p->data == NULL) + return 1; switch (p->data_size) { case sizeof(int32_t): if (val <= INT32_MAX) { @@ -335,6 +345,8 @@ int OSSL_PARAM_set_uint32(OSSL_PARAM *p, uint32_t val) } } else if (p->data_type == OSSL_PARAM_REAL) { p->return_size = sizeof(double); + if (p->data == NULL) + return 1; switch (p->data_size) { case sizeof(double): *(double *)p->data = (double)val; @@ -403,6 +415,8 @@ int OSSL_PARAM_set_int64(OSSL_PARAM *p, int64_t val) p->return_size = 0; if (p->data_type == OSSL_PARAM_INTEGER) { p->return_size = sizeof(int64_t); /* Expected size */ + if (p->data == NULL) + return 1; switch (p->data_size) { case sizeof(int32_t): if (val >= INT32_MIN && val <= INT32_MAX) { @@ -417,6 +431,8 @@ int OSSL_PARAM_set_int64(OSSL_PARAM *p, int64_t val) } } else if (p->data_type == OSSL_PARAM_UNSIGNED_INTEGER && val >= 0) { p->return_size = sizeof(uint64_t); /* Expected size */ + if (p->data == NULL) + return 1; switch (p->data_size) { case sizeof(uint32_t): if (val <= UINT32_MAX) { @@ -431,6 +447,8 @@ int OSSL_PARAM_set_int64(OSSL_PARAM *p, int64_t val) } } else if (p->data_type == OSSL_PARAM_REAL) { p->return_size = sizeof(double); + if (p->data == NULL) + return 1; switch (p->data_size) { case sizeof(double): u64 = val < 0 ? -val : val; @@ -506,6 +524,8 @@ int OSSL_PARAM_set_uint64(OSSL_PARAM *p, uint64_t val) if (p->data_type == OSSL_PARAM_UNSIGNED_INTEGER) { p->return_size = sizeof(uint64_t); /* Expected size */ + if (p->data == NULL) + return 1; switch (p->data_size) { case sizeof(uint32_t): if (val <= UINT32_MAX) { @@ -520,6 +540,8 @@ int OSSL_PARAM_set_uint64(OSSL_PARAM *p, uint64_t val) } } else if (p->data_type == OSSL_PARAM_INTEGER) { p->return_size = sizeof(int64_t); /* Expected size */ + if (p->data == NULL) + return 1; switch (p->data_size) { case sizeof(int32_t): if (val <= INT32_MAX) { @@ -616,6 +638,8 @@ int OSSL_PARAM_set_BN(OSSL_PARAM *p, const BIGNUM *val) bytes = (size_t)BN_num_bytes(val); p->return_size = bytes; + if (p->data == NULL) + return 1; return p->data_size >= bytes && BN_bn2nativepad(val, p->data, bytes) >= 0; } @@ -680,6 +704,8 @@ int OSSL_PARAM_set_double(OSSL_PARAM *p, double val) if (p->data_type == OSSL_PARAM_REAL) { p->return_size = sizeof(double); + if (p->data == NULL) + return 1; switch (p->data_size) { case sizeof(double): *(double *)p->data = val; @@ -688,6 +714,8 @@ int OSSL_PARAM_set_double(OSSL_PARAM *p, double val) } else if (p->data_type == OSSL_PARAM_UNSIGNED_INTEGER && val == (ossl_uintmax_t)val) { p->return_size = sizeof(double); + if (p->data == NULL) + return 1; switch (p->data_size) { case sizeof(uint32_t): if (val >= 0 && val <= UINT32_MAX) { @@ -705,6 +733,8 @@ int OSSL_PARAM_set_double(OSSL_PARAM *p, double val) break; } } else if (p->data_type == OSSL_PARAM_INTEGER && val == (ossl_intmax_t)val) { p->return_size = sizeof(double); + if (p->data == NULL) + return 1; switch (p->data_size) { case sizeof(int32_t): if (val >= INT32_MIN && val <= INT32_MAX) { @@ -775,6 +805,8 @@ static int set_string_internal(OSSL_PARAM *p, const void *val, size_t len, unsigned int type) { p->return_size = len; + if (p->data == NULL) + return 1; if (p->data_type != type || p->data_size < len) return 0; @@ -847,7 +879,8 @@ static int set_ptr_internal(OSSL_PARAM *p, const void *val, p->return_size = len; if (p->data_type != type) return 0; - *(const void **)p->data = val; + if (p->data != NULL) + *(const void **)p->data = val; return 1; } |