From 8a06db32ead073cffc76465c8a703d0c9bfd06d7 Mon Sep 17 00:00:00 2001 From: arkady-e1ppa Date: Tue, 8 Oct 2024 20:49:02 +0300 Subject: Fix missing early return in error's update tracing attributes method and UB in host name parcing commit_hash:cc382538d686689db47047d08624b01ac8893464 --- yt/yt/core/misc/error.cpp | 5 ++++- yt/yt/core/misc/stripped_error.cpp | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/yt/yt/core/misc/error.cpp b/yt/yt/core/misc/error.cpp index 8aff91e407b..950a7a0f022 100644 --- a/yt/yt/core/misc/error.cpp +++ b/yt/yt/core/misc/error.cpp @@ -69,7 +69,9 @@ void TryExtractHost(const TOriginAttributes& attributes) spanId ] = Decode(*attributes.ExtensionData); - attributes.Host = name; + attributes.Host = name + ? TStringBuf(name) + : TStringBuf{}; } //////////////////////////////////////////////////////////////////////////////// @@ -125,6 +127,7 @@ void UpdateTracingAttributes(TOriginAttributes* attributes, const NTracing::TTra .TraceId = tracingAttributes.TraceId, .SpanId = tracingAttributes.SpanId, })); + return; } attributes->ExtensionData.emplace(Encode(TExtensionData{ diff --git a/yt/yt/core/misc/stripped_error.cpp b/yt/yt/core/misc/stripped_error.cpp index c636ce9ce95..3406f61dac8 100644 --- a/yt/yt/core/misc/stripped_error.cpp +++ b/yt/yt/core/misc/stripped_error.cpp @@ -797,7 +797,21 @@ void AppendError(TStringBuilderBase* builder, const TError& error, int indent) for (const auto& [key, value] : error.Attributes().ListPairs()) { TTokenizer tokenizer(value.AsStringBuf()); - YT_VERIFY(tokenizer.ParseNext()); + // TODO(arkady-e1ppa): Remove this once failed verifies have been dealt with. + [[unlikely]] if (!tokenizer.ParseNext()) { + Cerr << + NYT::Format( + "%v *** Empty toke encountered while formatting TError attribute (Key: %v, Value: %v" + "(BuilderAccumulatedData: %v)", + TInstant::Now(), + key, + value.AsStringBuf(), + builder->GetBuffer()) + << '\n'; + Flush(Cerr); + YT_ABORT(); + } + // YT_VERIFY(tokenizer.ParseNext()); switch (tokenizer.GetCurrentType()) { case ETokenType::String: AppendAttribute(builder, key, TString(tokenizer.CurrentToken().GetStringValue()), indent); -- cgit v1.3