aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-06-29 11:11:57 -0400
committerJack Lloyd <[email protected]>2017-06-29 11:11:57 -0400
commit8b0986310ae9fdf7fa93e28e2820d818cc954cdd (patch)
tree4ab56b16516d7e9acce4551e9e93ea39d8114f51
parent705336f7bc01df0a345bdc0e58c36d01c7f467d3 (diff)
parent41a74f93ed08084fb84b97b52c281ffc83e9eb5a (diff)
Merge GH #1095 Catch exceptions in botan_mp_init
-rw-r--r--src/lib/ffi/ffi.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/lib/ffi/ffi.cpp b/src/lib/ffi/ffi.cpp
index f46d7ec11..38e3ba425 100644
--- a/src/lib/ffi/ffi.cpp
+++ b/src/lib/ffi/ffi.cpp
@@ -523,10 +523,30 @@ int botan_rng_reseed(botan_rng_t rng, size_t bits)
return BOTAN_FFI_DO(Botan::RandomNumberGenerator, rng, r, { r.reseed_from_rng(Botan::system_rng(), bits); });
}
-int botan_mp_init(botan_mp_t* mp)
+int botan_mp_init(botan_mp_t* mp_out)
{
- *mp = new botan_mp_struct(new Botan::BigInt);
- return 0;
+ try
+ {
+ BOTAN_ASSERT_ARG_NON_NULL(mp_out);
+
+ std::unique_ptr<Botan::BigInt> mp(new Botan::BigInt);
+
+ if(mp)
+ {
+ *mp_out = new botan_mp_struct(mp.release());
+ return 0;
+ }
+ }
+ catch(std::exception& e)
+ {
+ log_exception(BOTAN_CURRENT_FUNCTION, e.what());
+ }
+ catch(...)
+ {
+ log_exception(BOTAN_CURRENT_FUNCTION, "unknown");
+ }
+
+ return -1;
}
int botan_mp_clear(botan_mp_t mp)