Skip to content

Commit 7f8a2e9

Browse files
committed
YT-27235: Fix potential stack use-after-free issues in unittests
Change `ReturnRef` to `ReturnRefOfCopy`, since most of our mocks are ref-counted and may not necessarily be destroyed at the end of test scope. commit_hash:6783e2f1de0a909beff3a2535fd6216fdbcc9123
1 parent bfeffb7 commit 7f8a2e9

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

yt/yt/client/federated/unittests/client_ut.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ using namespace NYT::NApi;
2121
using ::testing::_;
2222
using ::testing::AnyNumber;
2323
using ::testing::Return;
24-
using ::testing::ReturnRef;
24+
using ::testing::ReturnRefOfCopy;
2525
using ::testing::StrictMock;
2626

2727
using TStrictMockClient = StrictMock<NApi::TMockClient>;
@@ -176,7 +176,7 @@ TEST(TFederatedClientTest, CheckHealth)
176176
auto mockConnectionVla = New<TStrictMockConnection>();
177177
std::optional<std::string> clusterName("vla-cluster");
178178
EXPECT_CALL(*mockConnectionVla, GetClusterName())
179-
.WillRepeatedly(ReturnRef(clusterName));
179+
.WillRepeatedly(ReturnRefOfCopy(clusterName));
180180

181181
auto mockClientVla = New<TStrictMockClient>();
182182
EXPECT_CALL(*mockClientVla, GetConnection())
@@ -470,7 +470,7 @@ TEST(TFederatedClientTest, AttachTransaction)
470470
.WillRepeatedly(Return(NObjectClient::TCellTag(123)));
471471
std::optional<std::string> clusterNameSas = "cluster-sas";
472472
EXPECT_CALL(*mockConnectionSas, GetClusterName())
473-
.WillRepeatedly(ReturnRef(clusterNameSas));
473+
.WillRepeatedly(ReturnRefOfCopy(clusterNameSas));
474474
EXPECT_CALL(*mockClientSas, GetConnection())
475475
.WillRepeatedly(Return(mockConnectionSas));
476476

@@ -479,7 +479,7 @@ TEST(TFederatedClientTest, AttachTransaction)
479479
.WillRepeatedly(Return(NObjectClient::TCellTag(456)));
480480
std::optional<std::string> clusterNameVla = "cluster-vla";
481481
EXPECT_CALL(*mockConnectionVla, GetClusterName())
482-
.WillRepeatedly(ReturnRef(clusterNameVla));
482+
.WillRepeatedly(ReturnRefOfCopy(clusterNameVla));
483483
EXPECT_CALL(*mockClientVla, GetConnection())
484484
.WillRepeatedly(Return(mockConnectionVla));
485485

0 commit comments

Comments
 (0)