Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protect against duplicate assembly statement labels #139

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/bpf_assembler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ typedef class _bpf_assembler
{"jsle", 0xd},
};

// Labels discoverd while parsing the assembly code.
// Labels discovered while parsing the assembly code.
std::unordered_map<std::string, size_t> _labels{};

// Vector of the same size as the assembly code, containing the label to
Expand Down Expand Up @@ -525,7 +525,13 @@ typedef class _bpf_assembler

// Check for labels.
if (mnemonic.ends_with(':')) {
_labels[mnemonic.substr(0, mnemonic.length() - 1)] = output.size();
auto label = mnemonic.substr(0, mnemonic.length() - 1);
if (_labels.contains(label)) {
std::stringstream ss{};
ss << "Duplicate label (" + label + ") detected at line " << output.size() << " (previous declaration at line " << _labels[label] << ")";
throw std::runtime_error(ss.str());
}
_labels[label] = output.size();
continue;
}

Expand Down