From ab3395e1df9b0ff557561a2431ca3624d7a4a1d0 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Thu, 5 Mar 2020 11:32:43 -0500 Subject: [PATCH] rgw: fix string_view formatting in RGWFormatter_Plain two string_views were being passed directly to vsnprintf where it expected null-terminated strings. the compiler didn't catch this, and resulted in segfaults string_views aren't guaranteed to be null-terminated, so printf formats have to specify a length as well Signed-off-by: Casey Bodley --- src/rgw/rgw_formats.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rgw/rgw_formats.cc b/src/rgw/rgw_formats.cc index 0c752f61c1e0..f9c0b9857430 100644 --- a/src/rgw/rgw_formats.cc +++ b/src/rgw/rgw_formats.cc @@ -128,7 +128,7 @@ void RGWFormatter_Plain::dump_float(std::string_view name, double d) void RGWFormatter_Plain::dump_string(std::string_view name, std::string_view s) { - dump_format(name, "%s", s.data()); + dump_format(name, "%.*s", s.size(), s.data()); } std::ostream& RGWFormatter_Plain::dump_stream(std::string_view name) @@ -166,7 +166,7 @@ void RGWFormatter_Plain::dump_format_va(std::string_view name, const char *ns, b wrote_something = true; if (use_kv && !entry.is_array) - write_data("%s%s: %s", eol, name, buf); + write_data("%s%.*s: %s", eol, name.size(), name.data(), buf); else write_data("%s%s", eol, buf); } @@ -276,7 +276,7 @@ void RGWFormatter_Plain::dump_value_int(std::string_view name, const char *fmt, wrote_something = true; if (use_kv && !entry.is_array) - write_data("%s%s: %s", eol, name, buf); + write_data("%s%.*s: %s", eol, name.size(), name.data(), buf); else write_data("%s%s", eol, buf); -- 2.47.3