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 Mar 2, 2022
1 parent b01ebab commit d387060
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 @@ -83,8 +83,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 @@ -36,6 +36,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 @@ -74,3 +74,17 @@ TEST(eof_validation, EOF1_data_section_0_size)
EXPECT_EQ(validate_eof(from_hex("EF0001 010001 020000 00 FE")),
EOFValidationErrror::zero_section_size);
}

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

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

0 comments on commit d387060

Please sign in to comment.