Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
[squash] use static zero-initialized buffer for padding
  • Loading branch information
addaleax committed Dec 19, 2017
commit 906b6b38beff7dec2241e52167eff72a5be28a01
13 changes: 6 additions & 7 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ namespace http2 {

namespace {

const char zero_bytes_256[256] = {};

inline Http2Stream* GetStream(Http2Session* session,
int32_t id,
nghttp2_data_source* source) {
Expand Down Expand Up @@ -1113,15 +1115,10 @@ void Http2Session::ClearOutgoing(int status) {
// Queue a given block of data for sending. This always creates a copy,
// so it is used for the cases in which nghttp2 requests sending of a
// small chunk of data.
// If src == nullptr, this zero-fills instead (which is useful for padding).
void Http2Session::CopyDataIntoOutgoing(const uint8_t* src, size_t src_length) {
size_t offset = outgoing_storage_.size();
outgoing_storage_.resize(offset + src_length);
if (src != nullptr) {
memcpy(&outgoing_storage_[offset], src, src_length);
} else {
memset(&outgoing_storage_[offset], 0, src_length);
}
memcpy(&outgoing_storage_[offset], src, src_length);

// Store with a base of `nullptr` initially, since future resizes
// of the outgoing_buffers_ vector may invalidate the pointer.
Expand Down Expand Up @@ -1269,7 +1266,9 @@ int Http2Session::OnSendData(

if (frame->data.padlen > 0) {
// Send padding if that was requested.
session->CopyDataIntoOutgoing(nullptr, frame->data.padlen - 1);
session->outgoing_buffers_.emplace_back(nghttp2_stream_write {
uv_buf_init(const_cast<char*>(zero_bytes_256), frame->data.padlen - 1)
});
}

return 0;
Expand Down