Added FC_ASSERT to prevent buffer overflow

This commit is contained in:
Peter Conrad 2015-07-26 17:27:12 +02:00
parent af18f89355
commit fe0ec4a42d
2 changed files with 10 additions and 3 deletions

View file

@ -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 ) ) {
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() );
return out.size();
}

View file

@ -5,6 +5,7 @@
#include <fc/crypto/base36.hpp>
#include <fc/crypto/base58.hpp>
#include <fc/crypto/base64.hpp>
#include <fc/exception/exception.hpp>
#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() ) );
char buffer[64];
size_t len = fc::from_base58( enc1, buffer, 16 );
BOOST_CHECK( len <= 16 );
size_t len = fc::from_base58( enc1, buffer, 64 );
BOOST_CHECK( len <= 64 );
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 ) {}
}
}