Skip to content

[SHIM] Dangerous use of string_viewΒ #3180

@chusitoo

Description

@chusitoo

The opentracing shim does a few conversions in either direction between the implementation of opentracing::string_view to nostd::string_view, by constructing the target with just the .data() part.

The approach might be OK as is, in general, but is highly speculative on the source buffer being null terminated. The alternative is explicitly constructing the target string view with the size of the buffer.

For instance, the proper mapping in shim_utils.h L32 would look like this:

-    AttributeValue operator()(opentracing::string_view v) { return nostd::string_view{v.data()}; }
+    AttributeValue operator()(opentracing::string_view v)
+    {
+      return nostd::string_view{v.data(), v.size()};
+    }

This would make it for the correct use of string view at the expense of a bit more verbosity.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriage/acceptedIndicates an issue or PR is ready to be actively worked on.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions