Skip to content

Commit

Permalink
Don't allow handling multiple code/data section in EOF1 validation
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Jul 15, 2021
1 parent 7a8b41c commit 0995f07
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/evmone/eof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,13 @@ std::pair<EOF1Header, EOFValidationErrror> validate_eof1(
case DATA_SECTION:
if (section_sizes[CODE_SECTION] == 0)
return {{}, EOFValidationErrror::code_section_missing};
[[fallthrough]];
if (section_sizes[DATA_SECTION] != 0)
return {{}, EOFValidationErrror::multiple_data_sections};
state = State::section_size;
break;
case CODE_SECTION:
if (section_sizes[CODE_SECTION] != 0)
return {{}, EOFValidationErrror::multiple_code_sections};
state = State::section_size;
break;
default:
Expand Down
2 changes: 2 additions & 0 deletions lib/evmone/eof.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ enum class EOFValidationErrror

incomplete_section_size,
code_section_missing,
multiple_code_sections,
multiple_data_sections,
unknown_section_id,
zero_section_size,
section_headers_not_terminated,
Expand Down
14 changes: 14 additions & 0 deletions test/unittests/eof_validation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,17 @@ TEST(eof_validation, EOF1_code_section_missing)
EXPECT_EQ(validate_eof(EVMC_SHANGHAI, from_hex("EFCAFE01 020001 DA")),
EOFValidationErrror::code_section_missing);
}

TEST(eof_validation, EOF1_multiple_code_sections)
{
EXPECT_EQ(validate_eof(EVMC_SHANGHAI, from_hex("EFCAFE01 010001 010001 00 FE FE")),
EOFValidationErrror::multiple_code_sections);
EXPECT_EQ(validate_eof(EVMC_SHANGHAI, from_hex("EFCAFE01 010001 010001 020001 00 FE FE DA")),
EOFValidationErrror::multiple_code_sections);
}

TEST(eof_validation, EOF1_multiple_data_sections)
{
EXPECT_EQ(validate_eof(EVMC_SHANGHAI, from_hex("EFCAFE01 010001 020001 020001 00 FE DA DA")),
EOFValidationErrror::multiple_data_sections);
}

0 comments on commit 0995f07

Please sign in to comment.