From b63c88aab7a732ab98a053cd036f33a1b12e3966 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Mon, 28 Mar 2016 22:22:26 +0900 Subject: [PATCH] nghttpx: Fix bug that logger wrote string which was not NULL-terminated --- src/shrpx_http2_downstream_connection.cc | 3 ++- src/shrpx_http2_upstream.cc | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/shrpx_http2_downstream_connection.cc b/src/shrpx_http2_downstream_connection.cc index c723b620..756180ef 100644 --- a/src/shrpx_http2_downstream_connection.cc +++ b/src/shrpx_http2_downstream_connection.cc @@ -444,7 +444,8 @@ int Http2DownstreamConnection::push_request_headers() { if (LOG_ENABLED(INFO)) { std::stringstream ss; for (auto &nv : nva) { - ss << TTY_HTTP_HD << nv.name << TTY_RST << ": " << nv.value << "\n"; + ss << TTY_HTTP_HD << StringRef{nv.name, nv.namelen} << TTY_RST << ": " + << StringRef{nv.value, nv.valuelen} << "\n"; } DCLOG(INFO, this) << "HTTP request headers\n" << ss.str(); } diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index dbec6c16..3eaa3368 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -1687,7 +1687,8 @@ void Http2Upstream::log_response_headers( Downstream *downstream, const std::vector &nva) const { std::stringstream ss; for (auto &nv : nva) { - ss << TTY_HTTP_HD << nv.name << TTY_RST << ": " << nv.value << "\n"; + ss << TTY_HTTP_HD << StringRef{nv.name, nv.namelen} << TTY_RST << ": " + << StringRef{nv.value, nv.valuelen} << "\n"; } ULOG(INFO, this) << "HTTP response headers. stream_id=" << downstream->get_stream_id() << "\n" << ss.str(); @@ -1860,7 +1861,8 @@ int Http2Upstream::submit_push_promise(const StringRef &scheme, if (LOG_ENABLED(INFO)) { std::stringstream ss; for (auto &nv : nva) { - ss << TTY_HTTP_HD << nv.name << TTY_RST << ": " << nv.value << "\n"; + ss << TTY_HTTP_HD << StringRef{nv.name, nv.namelen} << TTY_RST << ": " + << StringRef{nv.value, nv.valuelen} << "\n"; } ULOG(INFO, this) << "HTTP push request headers. promised_stream_id=" << promised_stream_id << "\n" << ss.str();