From 31d85a4f267263044c57ee29db04d511ccee2df1 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Mon, 21 Nov 2022 10:14:40 +0900 Subject: [PATCH] Fix wrong bundle_foreach implementation if data is removed through bundle_foreach(), A crash may occur. This patch resolves this by passing the iterator to the next before calling the callback using the iterator. Change-Id: I3f04418f47bc17247e857362b462e616c2136fa0 Signed-off-by: Changgyu Choi --- src/stub.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/stub.cc b/src/stub.cc index fdfc9dc..540ca4c 100644 --- a/src/stub.cc +++ b/src/stub.cc @@ -160,10 +160,12 @@ extern "C" EXPORT_API void bundle_foreach(bundle* b, } auto* h = reinterpret_cast(b); - for (const auto& kv : h->GetMap()) { - auto& key_info = kv.second; + auto it = h->GetMap().begin(); + while (it != h->GetMap().end()) { + auto& key_info = it->second; + ++it; callback(key_info->GetKey().c_str(), key_info->GetType(), - reinterpret_cast(key_info.get()), user_data); + reinterpret_cast(key_info.get()), user_data); } set_last_result(BUNDLE_ERROR_NONE); -- 2.7.4