Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Potential risk of not working get_block or get_block_header_state #7002

Closed
conr2d opened this issue Mar 27, 2019 · 2 comments
Closed

Potential risk of not working get_block or get_block_header_state #7002

conr2d opened this issue Mar 27, 2019 · 2 comments

Comments

@conr2d
Copy link
Contributor

conr2d commented Mar 27, 2019

@arhag

As you know, I wrote the patch for fc which throws an exception when the length of hex string (for vector<char>) is not even number. However, I found the risk that this patch makes RPC API get_block or get_block_header_state not work when it is merged to EOS repository.

In chain_plugin.cpp:

   try {
      block = db.fetch_block_by_id(fc::variant(params.block_num_or_id).as<block_id_type>());
      if (!block) {
         block = db.fetch_block_by_number(fc::to_uint64(params.block_num_or_id));
      }

} EOS_RETHROW_EXCEPTIONS(chain::block_id_type_exception, "Invalid block ID: ${block_num_or_id}", ("block_num_or_id", params.block_num_or_id))

In second line, there's no try-catch block for fc::variant(params.block_num_or_id).as<block_id_type>(), but when params.block_num_or_id is block_num (not block_id), and the number of its digits is odd, it throws an exception instead of executing db.fetch_block_by_number().

I think there can be several solutions for this.

  1. Add try-catch block in chain_plugin
  2. Allow odd-number length hex string
  3. Revert patch for simplicity (!)

I think the first solution is correct, but I can't assure that there will be no part written like this. The second solution seems safer.

@arhag
Copy link
Contributor

arhag commented Mar 27, 2019

This was already fixed in PR #6904.

@conr2d
Copy link
Contributor Author

conr2d commented Mar 27, 2019

@arhag Oh, God. I didn't knew it. I was worried my patch might cause some trouble. Thanks. :)

@conr2d conr2d closed this as completed Mar 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants