1
0
mirror of synced 2024-11-14 02:57:41 +01:00

nodes: Validate some buffer operations (#425)

* fix: NodeBufferSlice bounds validation

* fix: Make sure buffer is within u64 bounds in NodeCastBufferToInteger

* nodes: Use specific output methods in number constants
This commit is contained in:
Mark Nokalt 2022-02-08 04:32:10 -03:00 committed by GitHub
parent 37ea9c6656
commit a52fee2248
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 13 deletions

@ -1 +1 @@
Subproject commit 5d3273443a47f4a2f295cc476b5266a84e836206 Subproject commit 0842d22deb13e036eb1fb15df368b6cad552abfe

View File

@ -109,10 +109,7 @@ namespace hex::plugin::builtin {
} }
void process() override { void process() override {
std::vector<u8> data(sizeof(this->m_value), 0); this->setIntegerOnOutput(0, this->m_value);
std::memcpy(data.data(), &this->m_value, sizeof(u64));
this->setBufferOnOutput(0, data);
} }
void store(nlohmann::json &j) override { void store(nlohmann::json &j) override {
@ -140,11 +137,7 @@ namespace hex::plugin::builtin {
} }
void process() override { void process() override {
std::vector<u8> data; this->setFloatOnOutput(0, this->m_value);
data.resize(sizeof(this->m_value));
std::copy(&this->m_value, &this->m_value + 1, data.data());
this->setBufferOnOutput(0, data);
} }
void store(nlohmann::json &j) override { void store(nlohmann::json &j) override {
@ -427,8 +420,11 @@ namespace hex::plugin::builtin {
void process() override { void process() override {
auto input = this->getBufferOnInput(0); auto input = this->getBufferOnInput(0);
u64 output; if (input.size() == 0 || input.size() > sizeof(u64))
std::memcpy(&output, input.data(), sizeof(u64)); throwNodeError("Buffer is empty or bigger than 64 bits");
u64 output = 0;
std::memcpy(&output, input.data(), input.size());
this->setIntegerOnOutput(1, output); this->setIntegerOnOutput(1, output);
} }
@ -538,7 +534,7 @@ namespace hex::plugin::builtin {
throwNodeError("'from' input out of range"); throwNodeError("'from' input out of range");
if (to < 0 || from >= input.size()) if (to < 0 || from >= input.size())
throwNodeError("'to' input out of range"); throwNodeError("'to' input out of range");
if (to >= from) if (to <= from)
throwNodeError("'to' input needs to be greater than 'from' input"); throwNodeError("'to' input needs to be greater than 'from' input");
this->setBufferOnOutput(3, std::vector(input.begin() + from, input.begin() + to)); this->setBufferOnOutput(3, std::vector(input.begin() + from, input.begin() + to));