Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Add oneof case bound check #1502

Merged
merged 7 commits into from
Jul 3, 2018
Merged

Add oneof case bound check #1502

merged 7 commits into from
Jul 3, 2018

Conversation

l4l
Copy link
Contributor

@l4l l4l commented Jun 26, 2018

Description of the Change

Command/Query cases aren't properly validated

Benefits

Lesser bugs

Possible Drawbacks

Validators now require protobuf backend objects but should be fixed with IR-1040

@l4l l4l added needs-review pr awaits review from maintainers bug bug/defect that was reproduced by maintainers query All that relates to the iroha querying command All that relates to the commands performing at iroha labels Jun 26, 2018
@l4l l4l requested review from Solonets and lebdron June 26, 2018 19:08
Copy link
Contributor

@lebdron lebdron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add test which cover untyped command and query using generated protobuf builders.

static_cast<const shared_model::proto::Command &>(command)
.getTransport()
.command_case();
if (cmd_begin > cmd_case || cmd_case >= cmd_end) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as in query, getTransport().has_command() is simpler and covers the desired case.

.getTransport()
.payload()
.query_case();
if (qry_begin > qry_case || qry_case >= qry_end) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

payload().has_query() can be used instead, since it's simpler and covers the case.

@l4l l4l changed the title Fix/vars case Add oneof case bound check Jun 28, 2018
@l4l l4l requested review from kamilsa and removed request for Solonets June 29, 2018 12:39
@sorabot
Copy link

sorabot commented Jun 29, 2018

@sorabot
Copy link

sorabot commented Jun 29, 2018

*/
TEST_F(QueryValidatorTest, UnsetQuery) {
iroha::protocol::Query qry;
auto *meta = new iroha::protocol::QueryPayloadMeta();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use mutable_meta instead to avoid new call.

tx.mutable_payload()->set_creator_account_id(account_id);
tx.mutable_payload()->set_created_time(created_time);
auto answer = transaction_validator.validate(proto::Transaction(tx));
ASSERT_TRUE(answer.hasErrors());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Answer here is Transaction: [[Transaction should contain at least one command ]], which is not the described case.
There should be an additional call tx.mutable_payload()->add_commands();

Signed-off-by: Kitsu <[email protected]>
tx.mutable_payload()->set_creator_account_id(account_id);
tx.mutable_payload()->set_created_time(created_time);
auto answer = transaction_validator.validate(proto::Transaction(tx));
tx.mutable_payload()->add_commands()->clear_add_asset_quantity();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussion, it seems that clear_add_asset_quantity() is redundant, since add_commands() does not set add_asset_quantity by default, and compiler won't probably optimize any calls. So clear_add_asset_quantity() call can be removed.

@sorabot
Copy link

sorabot commented Jun 30, 2018

@sorabot
Copy link

sorabot commented Jun 30, 2018

@l4l l4l removed the needs-review pr awaits review from maintainers label Jul 2, 2018
@l4l l4l merged commit 0712731 into develop Jul 3, 2018
@l4l l4l deleted the fix/vars_case branch July 3, 2018 09:38
@l4l l4l mentioned this pull request Jul 10, 2018
l4l added a commit that referenced this pull request Jul 25, 2018
* Add check for Command variant case
* Add check for Query variant case
* Add related tests

Signed-off-by: Kitsu <[email protected]>
l4l added a commit that referenced this pull request Jul 25, 2018
* Add check for Command variant case
* Add check for Query variant case
* Add related tests

Signed-off-by: Kitsu <[email protected]>
l4l added a commit that referenced this pull request Jul 25, 2018
* Add check for Command variant case
* Add check for Query variant case
* Add related tests

Signed-off-by: Kitsu <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug bug/defect that was reproduced by maintainers command All that relates to the commands performing at iroha query All that relates to the iroha querying
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants