-
Notifications
You must be signed in to change notification settings - Fork 432
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
[CRASH] Segmentation fault in LogRecordSetterTrait<EventId>
for events without a name
#3177
Comments
For this particular bug, the fix could be diff --git a/api/include/opentelemetry/logs/logger_type_traits.h b/api/include/opentelemetry/logs/logger_type_traits.h
index d88a6ffb..83a78c4d 100644
--- a/api/include/opentelemetry/logs/logger_type_traits.h
+++ b/api/include/opentelemetry/logs/logger_type_traits.h
@@ -47,7 +47,7 @@ struct LogRecordSetterTrait<EventId>
template <class ArgumentType>
inline static LogRecord *Set(LogRecord *log_record, ArgumentType &&arg) noexcept
{
- log_record->SetEventId(arg.id_, nostd::string_view{arg.name_.get()});
+ log_record->SetEventId(arg.id_, nostd::string_view{arg.name_ ? arg.name_.get() : ""});
return log_record;
} However, it would be interesting to try to find other places where a similar bug is present. |
Another possible bug: https://github.com/sjinks/opentelemetry-cpp/blob/f1b5fbdedd5beb7e7ca6aacfb3f430686d694d9c/exporters/etw/include/opentelemetry/exporters/etw/etw_properties.h#L303-L304 const char *data = nostd::get<const char *>(*this);
return nostd::string_view(data, (data) ? strlen(data) : 0); In C++17, when Maybe - return nostd::string_view(data, (data) ? strlen(data) : 0);
+ return data ? nostd::string_view(data, strlen(data)) : nostd::string_view(); |
Thanks, @ThomsonTan I'm not sure about the specification of event id. could you please check if it's OK to let event name be empty or set a default name?
In my understanding, a event only has |
Describe your environment opentelemetry-cpp v1.18.0 (I found this bug in v1.11.0)
Steps to reproduce
What is the expected behavior?
No crash
What is the actual behavior?
Segmentation fault
Additional context
EventId
is created with an emptyname_
:EventId(int64_t id) noexcept : id_{id}, name_{nullptr} {}
(ref)EventId
is passed toLogger::Info()
, then toEmitLogRecord()
.LogRecordSetterTrait<EventId>
is invoked to set the Event ID for theLogRecord
:log_record->SetEventId(arg.id_, nostd::string_view{arg.name_.get()});
(ref)EventId::name_
holds anullptr
value,nostd::string_view()
is constructed withnullptr
.nostd::string_view::string_view(const char*)
gets invoked, and it callsstd::strlen()
on anullptr
, crashing the application.The text was updated successfully, but these errors were encountered: