diff options
author | Daniel Wyatt <[email protected]> | 2017-04-26 11:19:05 -0400 |
---|---|---|
committer | Daniel Wyatt <[email protected]> | 2017-04-26 11:26:28 -0400 |
commit | e095f78432381666a0465755ff62ad6e70fa1c68 (patch) | |
tree | 658ab7e135417e4e3b23bb893f2853e4fb3fd94a | |
parent | 3a560e25b2ab197e54935eb047090446be6c10f5 (diff) |
Add explicit return to FFI botan_mp_to_str.
This way we know if the buffer is insufficient.
-rw-r--r-- | src/lib/ffi/ffi.cpp | 2 | ||||
-rw-r--r-- | src/tests/test_ffi.cpp | 3 |
2 files changed, 4 insertions, 1 deletions
diff --git a/src/lib/ffi/ffi.cpp b/src/lib/ffi/ffi.cpp index e15594ca6..42b01be62 100644 --- a/src/lib/ffi/ffi.cpp +++ b/src/lib/ffi/ffi.cpp @@ -553,7 +553,7 @@ int botan_mp_to_str(const botan_mp_t mp, uint8_t digit_base, char* out, size_t* std::vector<uint8_t> hex = Botan::BigInt::encode(bn, base); hex.push_back(0); // null terminator - write_str_output(out, out_len, hex); + return write_str_output(out, out_len, hex); }); } diff --git a/src/tests/test_ffi.cpp b/src/tests/test_ffi.cpp index 48d7c28c4..d5ddace04 100644 --- a/src/tests/test_ffi.cpp +++ b/src/tests/test_ffi.cpp @@ -780,6 +780,9 @@ class FFI_Unit_Tests : public Test TEST_FFI_OK(botan_mp_to_str, (r, 10, str_buf, &str_len)); result.test_eq("botan_mp_mod_mul", std::string(str_buf), "123945920473931248854653259523111998693"); + str_len = 0; + TEST_FFI_RC(BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE, botan_mp_to_str, (r, 10, str_buf, &str_len)); + size_t x_bytes; botan_mp_rand_bits(x, rng, 512); TEST_FFI_OK(botan_mp_num_bytes, (x, &x_bytes)); |