From 9526f649bfdc5d7f18e30948159de8ecfb0ebab4 Mon Sep 17 00:00:00 2001 From: Roy Keene Date: Wed, 2 Jan 2019 16:52:12 -0600 Subject: [PATCH] Zero-terminate all things we refer to as strings (#1223) --- nano/core_test/interface.cpp | 2 +- nano/lib/interface.cpp | 6 +++--- nano/lib/interface.h | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/nano/core_test/interface.cpp b/nano/core_test/interface.cpp index 560cd3b4..82cedb92 100644 --- a/nano/core_test/interface.cpp +++ b/nano/core_test/interface.cpp @@ -26,7 +26,7 @@ TEST (interface, xrb_uint256_to_string) TEST (interface, xrb_uint256_to_address) { nano::uint256_union zero (0); - char text[65] = { 0 }; + char text[66] = { 0 }; xrb_uint256_to_address (zero.bytes.data (), text); ASSERT_STREQ ("xrb_1111111111111111111111111111111111111111111111111111hifc8npp", text); } diff --git a/nano/lib/interface.cpp b/nano/lib/interface.cpp index e6a3209a..c03ff0ff 100644 --- a/nano/lib/interface.cpp +++ b/nano/lib/interface.cpp @@ -18,13 +18,13 @@ extern "C" { void xrb_uint128_to_dec (xrb_uint128 source, char * destination) { auto const & number (*reinterpret_cast (source)); - strncpy (destination, number.to_string_dec ().c_str (), 32); + strncpy (destination, number.to_string_dec ().c_str (), 40); } void xrb_uint256_to_string (xrb_uint256 source, char * destination) { auto const & number (*reinterpret_cast (source)); - strncpy (destination, number.to_string ().c_str (), 64); + strncpy (destination, number.to_string ().c_str (), 65); } void xrb_uint256_to_address (xrb_uint256 source, char * destination) @@ -36,7 +36,7 @@ void xrb_uint256_to_address (xrb_uint256 source, char * destination) void xrb_uint512_to_string (xrb_uint512 source, char * destination) { auto const & number (*reinterpret_cast (source)); - strncpy (destination, number.to_string ().c_str (), 128); + strncpy (destination, number.to_string ().c_str (), 129); } int xrb_uint128_from_dec (const char * source, xrb_uint128 destination) diff --git a/nano/lib/interface.h b/nano/lib/interface.h index 457891dc..cb5d726a 100644 --- a/nano/lib/interface.h +++ b/nano/lib/interface.h @@ -10,13 +10,13 @@ typedef unsigned char * xrb_uint256; // 32byte array for public and private keys typedef unsigned char * xrb_uint512; // 64byte array for signatures typedef void * xrb_transaction; -// Convert amount bytes 'source' to a 39 byte not-null-terminated decimal string 'destination' +// Convert amount bytes 'source' to a 40 byte null-terminated decimal string 'destination' void xrb_uint128_to_dec (const xrb_uint128 source, char * destination); -// Convert public/private key bytes 'source' to a 64 byte not-null-terminated hex string 'destination' +// Convert public/private key bytes 'source' to a 65 byte null-terminated hex string 'destination' void xrb_uint256_to_string (const xrb_uint256 source, char * destination); -// Convert public key bytes 'source' to a 65 byte non-null-terminated account string 'destination' +// Convert public key bytes 'source' to a 66 byte non-null-terminated account string 'destination' void xrb_uint256_to_address (xrb_uint256 source, char * destination); -// Convert public/private key bytes 'source' to a 128 byte not-null-terminated hex string 'destination' +// Convert public/private key bytes 'source' to a 129 byte null-terminated hex string 'destination' void xrb_uint512_to_string (const xrb_uint512 source, char * destination); // Convert 39 byte decimal string 'source' to a byte array 'destination'