提交 2aa4bed9 编写于 作者: K Kevin Heifner

Limit assert message to 1024 chars

上级 23b06b7f
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <fstream> #include <fstream>
#include <string.h>
namespace eosio { namespace chain { namespace eosio { namespace chain {
using namespace webassembly; using namespace webassembly;
...@@ -901,6 +902,8 @@ class system_api : public context_aware_api { ...@@ -901,6 +902,8 @@ class system_api : public context_aware_api {
}; };
constexpr size_t max_assert_message = 1024;
class context_free_system_api : public context_aware_api { class context_free_system_api : public context_aware_api {
public: public:
explicit context_free_system_api( apply_context& ctx ) explicit context_free_system_api( apply_context& ctx )
...@@ -913,14 +916,16 @@ public: ...@@ -913,14 +916,16 @@ public:
// Kept as intrinsic rather than implementing on WASM side (using eosio_assert_message and strlen) because strlen is faster on native side. // Kept as intrinsic rather than implementing on WASM side (using eosio_assert_message and strlen) because strlen is faster on native side.
void eosio_assert( bool condition, null_terminated_ptr msg ) { void eosio_assert( bool condition, null_terminated_ptr msg ) {
if( BOOST_UNLIKELY( !condition ) ) { if( BOOST_UNLIKELY( !condition ) ) {
std::string message( msg ); const size_t sz = strnlen( msg, max_assert_message );
std::string message( msg, sz );
EOS_THROW( eosio_assert_message_exception, "assertion failure with message: ${s}", ("s",message) ); EOS_THROW( eosio_assert_message_exception, "assertion failure with message: ${s}", ("s",message) );
} }
} }
void eosio_assert_message( bool condition, array_ptr<const char> msg, size_t msg_len ) { void eosio_assert_message( bool condition, array_ptr<const char> msg, size_t msg_len ) {
if( BOOST_UNLIKELY( !condition ) ) { if( BOOST_UNLIKELY( !condition ) ) {
std::string message( msg, msg_len ); const size_t sz = msg_len > max_assert_message ? max_assert_message : msg_len;
std::string message( msg, sz );
EOS_THROW( eosio_assert_message_exception, "assertion failure with message: ${s}", ("s",message) ); EOS_THROW( eosio_assert_message_exception, "assertion failure with message: ${s}", ("s",message) );
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册