Added FC_ASSERT to prevent buffer overflow
This commit is contained in:
parent
af18f89355
commit
fe0ec4a42d
2 changed files with 10 additions and 3 deletions
|
|
@ -631,7 +631,7 @@ size_t from_base58( const std::string& base58_str, char* out_data, size_t out_da
|
||||||
if( !DecodeBase58( base58_str.c_str(), out ) ) {
|
if( !DecodeBase58( base58_str.c_str(), out ) ) {
|
||||||
FC_THROW_EXCEPTION( parse_error_exception, "Unable to decode base58 string ${base58_str}", ("base58_str",base58_str) );
|
FC_THROW_EXCEPTION( parse_error_exception, "Unable to decode base58 string ${base58_str}", ("base58_str",base58_str) );
|
||||||
}
|
}
|
||||||
|
FC_ASSERT( out.size() <= out_data_len );
|
||||||
memcpy( out_data, out.data(), out.size() );
|
memcpy( out_data, out.data(), out.size() );
|
||||||
return out.size();
|
return out.size();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include <fc/crypto/base36.hpp>
|
#include <fc/crypto/base36.hpp>
|
||||||
#include <fc/crypto/base58.hpp>
|
#include <fc/crypto/base58.hpp>
|
||||||
#include <fc/crypto/base64.hpp>
|
#include <fc/crypto/base64.hpp>
|
||||||
|
#include <fc/exception/exception.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
@ -94,9 +95,15 @@ static void test_58( const std::string& test, const std::string& expected )
|
||||||
BOOST_CHECK( !memcmp( vec.data(), dec.data(), vec.size() ) );
|
BOOST_CHECK( !memcmp( vec.data(), dec.data(), vec.size() ) );
|
||||||
|
|
||||||
char buffer[64];
|
char buffer[64];
|
||||||
size_t len = fc::from_base58( enc1, buffer, 16 );
|
size_t len = fc::from_base58( enc1, buffer, 64 );
|
||||||
BOOST_CHECK( len <= 16 );
|
BOOST_CHECK( len <= 64 );
|
||||||
BOOST_CHECK( !memcmp( vec.data(), buffer, len ) );
|
BOOST_CHECK( !memcmp( vec.data(), buffer, len ) );
|
||||||
|
if ( len > 10 ) {
|
||||||
|
try {
|
||||||
|
len = fc::from_base58( enc1, buffer, 10 );
|
||||||
|
BOOST_CHECK( len <= 10 );
|
||||||
|
} catch ( fc::exception expected ) {}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue