From da521631b6710d6679ed3a59d7034f4c30d7179b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kr=C3=BCgler?= Date: Sat, 16 Sep 2023 14:19:04 +0200 Subject: [PATCH] New issue from Hewill Kang: "Issues with join_with_view::iterator's iter_swap" --- xml/issue3972.xml | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 xml/issue3972.xml diff --git a/xml/issue3972.xml b/xml/issue3972.xml new file mode 100644 index 0000000000..4d479909dc --- /dev/null +++ b/xml/issue3972.xml @@ -0,0 +1,38 @@ + + + + +Issues with <tt>join_with_view::<i>iterator</i></tt>'s <tt>iter_swap</tt> +
+Hewill Kang +04 Sep 2023 +99 + + +

+The iter_swap customization for join_with_view::iterator allows swapping iterators +with different element types, potentially leading to unsafe behavior, for example: +

+
+
+vector<vector<string>> x{{"a"}, {"b"}, {"c"}};
+vector<string_view>    y{"-"};
+auto r = x | views::join_with(y);
+auto i = r.begin();
+auto j = ranges::next(i);
+ranges::iter_swap(j, i);
+for (auto&& elem : r)
+  cout << elem << " "; // AddressSanitizer: stack-use-after-return on address
+
+
+

+The above swaps two iterators whose reference are string_view& and string& respectively, +which ultimately results in string_view being referenced to a local variable and left dangling. +

+
+ + + + + +