From 02af8f1fb17f3adfe7addc92539a282fede27da0 Mon Sep 17 00:00:00 2001 From: MarkLee131 Date: Mon, 30 Mar 2026 22:27:30 +0800 Subject: [PATCH] re2: guard against self-move-assignment in Set and FilteredRE2 The move assignment operators for RE2::Set and FilteredRE2 use a destroy-then-placement-new pattern. This is unsafe when this == &other because the destructor frees resources that the move constructor then tries to read from. Add a self-assignment check to both operators. --- re2/filtered_re2.cc | 6 ++++-- re2/set.cc | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/re2/filtered_re2.cc b/re2/filtered_re2.cc index f0995a10b..e87ffc609 100644 --- a/re2/filtered_re2.cc +++ b/re2/filtered_re2.cc @@ -43,8 +43,10 @@ FilteredRE2::FilteredRE2(FilteredRE2&& other) } FilteredRE2& FilteredRE2::operator=(FilteredRE2&& other) { - this->~FilteredRE2(); - (void) new (this) FilteredRE2(std::move(other)); + if (this != &other) { + this->~FilteredRE2(); + (void) new (this) FilteredRE2(std::move(other)); + } return *this; } diff --git a/re2/set.cc b/re2/set.cc index 3f2a1f078..9064a96ef 100644 --- a/re2/set.cc +++ b/re2/set.cc @@ -50,8 +50,10 @@ RE2::Set::Set(Set&& other) } RE2::Set& RE2::Set::operator=(Set&& other) { - this->~Set(); - (void) new (this) Set(std::move(other)); + if (this != &other) { + this->~Set(); + (void) new (this) Set(std::move(other)); + } return *this; }