Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SHIM] Dangerous use of string_view #3180

Closed
chusitoo opened this issue Dec 2, 2024 · 1 comment · Fixed by #3181
Closed

[SHIM] Dangerous use of string_view #3180

chusitoo opened this issue Dec 2, 2024 · 1 comment · Fixed by #3181
Labels
bug Something isn't working triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@chusitoo
Copy link
Contributor

chusitoo commented Dec 2, 2024

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.

@chusitoo chusitoo added the bug Something isn't working label Dec 2, 2024
@github-actions github-actions bot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Dec 2, 2024
@marcalff
Copy link
Member

marcalff commented Dec 2, 2024

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

This also improves performances, saving a call to strlen().

@marcalff marcalff added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants