aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/ffi/ffi.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-04-03 11:11:03 -0400
committerJack Lloyd <[email protected]>2017-04-03 11:11:03 -0400
commitcc8d2eec88c8744152931b34d28619e7fc6e26db (patch)
tree35997d1089510cd1cf0eefa7ad91442dd9040728 /src/lib/ffi/ffi.cpp
parentd93a1ad12e4bd872a687ea31329efd2c9878c8d9 (diff)
Fix botan_privkey_create if the desired algorithm was not available in build
If DSA was disabled, caused memory corruption/crashes due to combination of uninitialized object and the tests not checking return values as carefully as they should.
Diffstat (limited to 'src/lib/ffi/ffi.cpp')
-rw-r--r--src/lib/ffi/ffi.cpp35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/lib/ffi/ffi.cpp b/src/lib/ffi/ffi.cpp
index f067db75b..390afae81 100644
--- a/src/lib/ffi/ffi.cpp
+++ b/src/lib/ffi/ffi.cpp
@@ -980,20 +980,31 @@ int botan_privkey_create(botan_privkey_t* key_obj,
{
try
{
- if(key_obj == nullptr || rng_obj == nullptr)
- return -1;
+ if(key_obj == nullptr)
+ return BOTAN_FFI_ERROR_NULL_POINTER;
+
+ *key_obj = nullptr;
+ if(rng_obj == nullptr)
+ return BOTAN_FFI_ERROR_NULL_POINTER;
+
if(algo_name == nullptr)
algo_name = "RSA";
if(algo_params == nullptr)
algo_params = "";
- *key_obj = nullptr;
-
Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
std::unique_ptr<Botan::Private_Key> key(
Botan::create_private_key(algo_name, rng, algo_params));
- *key_obj = new botan_privkey_struct(key.release());
- return 0;
+
+ if(key)
+ {
+ *key_obj = new botan_privkey_struct(key.release());
+ return 0;
+ }
+ else
+ {
+ return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
+ }
}
catch(std::exception& e)
{
@@ -1215,6 +1226,10 @@ int botan_privkey_load_dsa(botan_privkey_t* key,
}
return -1;
#else
+ BOTAN_UNUSED(p);
+ BOTAN_UNUSED(q);
+ BOTAN_UNUSED(g);
+ BOTAN_UNUSED(x);
return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
#endif
}
@@ -1238,6 +1253,10 @@ int botan_pubkey_load_dsa(botan_pubkey_t* key,
return -1;
#else
+ BOTAN_UNUSED(p);
+ BOTAN_UNUSED(q);
+ BOTAN_UNUSED(g);
+ BOTAN_UNUSED(y);
return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
#endif
}
@@ -1365,7 +1384,7 @@ int botan_pubkey_get_field(botan_mp_t output,
botan_pubkey_t key,
const char* field_name_cstr)
{
- if(field_name_cstr == NULL)
+ if(field_name_cstr == nullptr)
return BOTAN_FFI_ERROR_NULL_POINTER;
const std::string field_name(field_name_cstr);
@@ -1379,7 +1398,7 @@ int botan_privkey_get_field(botan_mp_t output,
botan_privkey_t key,
const char* field_name_cstr)
{
- if(field_name_cstr == NULL)
+ if(field_name_cstr == nullptr)
return BOTAN_FFI_ERROR_NULL_POINTER;
const std::string field_name(field_name_cstr);