Skip to content

Instantly share code, notes, and snippets.

@fuzz-ai
Last active December 18, 2018 05:55
Show Gist options
  • Select an option

  • Save fuzz-ai/bd945c32265641b4981c560f90dcca2a to your computer and use it in GitHub Desktop.

Select an option

Save fuzz-ai/bd945c32265641b4981c560f90dcca2a to your computer and use it in GitHub Desktop.
const int buf_size = MAX_MESSAGE_SIZE + 1024;
char buf[buf_size];
int main( int argc, char *argv[] ) {
std::cin.read( buf, buf_size );
if ( !std::cin.eof() ) {
std::cout << "String too long.\n";
return 1;
}
size_t size = std::cin.gcount();
try {
message m;
// Message size and type will be filled in so that they match how
// many bytes we actually filled, and so that the type matches the
// decode function we're trying to use.
//
// m.size does *not* include the header, according to the original code..
//
// Data is padded on the wire but shortened to m.size before
// demarshaling.
m.size = fc::min( size, (size_t)MAX_MESSAGE_SIZE );
m.data.resize( m.size );
std::copy( buf, buf + m.size, m.data.begin() );
m.msg_type = graphene::net::hello_message_type;
graphene::net::hello_message hello = m.as<graphene::net::hello_message>();
} catch ( fc::exception &e ) {
std::cout << e.to_string() << "\n";
return 1;
} catch ( std::bad_alloc &e ) {
std::cout << "Out of memory!";
abort();
}
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment