From: Casey Bodley Date: Thu, 5 Mar 2020 16:32:43 +0000 (-0500) Subject: rgw: fix string_view formatting in RGWFormatter_Plain X-Git-Tag: v15.1.1~87^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F33754%2Fhead;p=ceph.git 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 --- 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);