Skip to content

Fix mismatched allocation with empty string keys and payloads #1132

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions src/producer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* of the MIT license. See the LICENSE.txt file for details.
*/

#include <array>
#include <string>
#include <vector>

Expand Down Expand Up @@ -474,6 +475,7 @@ NAN_METHOD(Producer::NodeProduce) {

size_t message_buffer_length;
void* message_buffer_data;
static std::array<char, 1> empty_string{'\0'};

if (info[2]->IsNull()) {
// This is okay for whatever reason
Expand All @@ -497,9 +499,8 @@ NAN_METHOD(Producer::NodeProduce) {
message_buffer_data = node::Buffer::Data(message_buffer_object);
if (message_buffer_data == NULL) {
// empty string message buffer should not end up as null message
v8::Local<v8::Object> message_buffer_object_emptystring = Nan::NewBuffer(new char[0], 0).ToLocalChecked();
message_buffer_length = node::Buffer::Length(message_buffer_object_emptystring);
message_buffer_data = node::Buffer::Data(message_buffer_object_emptystring);
message_buffer_length = 0;
message_buffer_data = reinterpret_cast<void*>(empty_string.data());
}
}

Expand Down Expand Up @@ -527,9 +528,8 @@ NAN_METHOD(Producer::NodeProduce) {
key_buffer_data = node::Buffer::Data(key_buffer_object);
if (key_buffer_data == NULL) {
// empty string key buffer should not end up as null key
v8::Local<v8::Object> key_buffer_object_emptystring = Nan::NewBuffer(new char[0], 0).ToLocalChecked();
key_buffer_length = node::Buffer::Length(key_buffer_object_emptystring);
key_buffer_data = node::Buffer::Data(key_buffer_object_emptystring);
key_buffer_length = 0;
key_buffer_data = reinterpret_cast<void*>(empty_string.data());
}
} else {
// If it was a string just use the utf8 value.
Expand Down