[M120][WRTjs] Add flag to check context_data initialized or not 22/305422/3
authorChunling Ye <chunling.ye@samsung.com>
Tue, 23 Jan 2024 06:23:41 +0000 (14:23 +0800)
committerDongHyun Song <dh81.song@samsung.com>
Fri, 2 Feb 2024 04:26:39 +0000 (04:26 +0000)
To avoid visit the invalid uninitialized memory, need add
flag to check context_data initialized or not.

Reference:
https://review.tizen.org/gerrit/#/c/platform/framework/web/chromium-efl/+/304681/

Change-Id: I91c9d4c45259591896dbc0f15fa7689cd51d0d0b
Signed-off-by: Chunling Ye <chunling.ye@samsung.com>
(cherry picked from commit ce59489a22b4f7b3a1e7184520a49b697c6251e5)

tizen_src/chromium_impl/components/xwalk_extensions/renderer/xwalk_extension_renderer_controller.cc
tizen_src/chromium_impl/components/xwalk_extensions/renderer/xwalk_extension_renderer_controller.h

index 1620fa4de6c7cfefe0e1be8eebbf7b2c93c5895e..6de062f64caa66628603879f508918a55e10e90d 100644 (file)
@@ -132,11 +132,13 @@ void XWalkExtensionRendererController::Initialize(
 // static
 void XWalkExtensionRendererController::DidCreateScriptContext(
     v8::Local<v8::Context> context) {
+  base::AutoLock lock(script_context_lock);
   // Initialize context's aligned pointer in embedder data with nullptr
   // This should be handled even if 'is_shutdown_' = true, otherise,
   // GetAlignedPointerFromEmbedderData can give invalid uninitialized memory.
-  base::AutoLock lock(script_context_lock);
   XWalkExtensionContextData::SetContextData(nullptr, context);
+  auto& controller = GetInstance();
+  controller.context_data_initialized = true;
 
   // Skip plugin loading after application exit request.
   if (is_shutdown_)
@@ -184,7 +186,6 @@ void XWalkExtensionRendererController::DidCreateScriptContext(
         "objecttools", base::WrapUnique(new ObjectToolsModule));
   }
 
-  auto& controller = GetInstance();
   controller.Initialize(execution_context);
 
   for (auto& it : controller.description_map_) {
@@ -207,6 +208,14 @@ void XWalkExtensionRendererController::DidCreateScriptContext(
 void XWalkExtensionRendererController::WillReleaseScriptContext(
     v8::Local<v8::Context> context) {
   base::AutoLock lock(script_context_lock);
+  // if context_data not initialize, when GetAlignedPointerFromEmbedderData
+  // can give invalid uninitialized memory.
+  auto& controller = GetInstance();
+  if (!controller.context_data_initialized) {
+    LOG(ERROR) << "context_data not initialize!";
+    return;
+  }
+
   v8::Context::Scope context_scope(context);
   XWalkExtensionContextData::DeleteContextData(context);
 }
index d7a878cbf3e0af7a0c82d92c30414c4fb3ccf9f2..b026b9f0076bafd0d80afed77ce6647759ef7206 100644 (file)
@@ -93,6 +93,8 @@ class XWalkExtensionRendererController : public mojom::XWalkExtensionRenderer {
   mojo::Receiver<mojom::XWalkExtensionRenderer> receiver_{this};
   absl::optional<uint64_t> receiver_id_;
   mojo::Remote<mojom::XWalkExtensionBrowser> browser_;
+
+  bool context_data_initialized = false;
   bool offload_enabled_ = false;
 };