[tbb-commits] [Git][tpo/applications/tor-browser][base-browser-115.1.0esr-13.0-1] Bug 42022: Prevent extension search engines from breaking the whole search system

Pier Angelo Vendrame (@pierov) git at gitlab.torproject.org
Wed Aug 16 17:44:25 UTC 2023



Pier Angelo Vendrame pushed to branch base-browser-115.1.0esr-13.0-1 at The Tor Project / Applications / Tor Browser


Commits:
d11b0294 by Pier Angelo Vendrame at 2023-08-16T19:44:09+02:00
Bug 42022: Prevent extension search engines from breaking the whole search system

We found that if an extension tries to add a search engine that is
already bundled the whole search system breaks because an exception is
thrown and it reaches the initialization function, whose catch undoes
the initialization.

With this commit, we handle this kind of exceptions when trying to
install the extension's engines, and contain it there.

- - - - -


1 changed file:

- toolkit/components/search/SearchService.sys.mjs


Changes:

=====================================
toolkit/components/search/SearchService.sys.mjs
=====================================
@@ -2706,6 +2706,7 @@ export class SearchService {
     };
 
     let engines = [];
+    let revert = false;
     for (let locale of locales) {
       lazy.logConsole.debug(
         "addEnginesFromExtension: installing:",
@@ -2713,7 +2714,28 @@ export class SearchService {
         ":",
         locale
       );
-      engines.push(await installLocale(locale));
+      try {
+        engines.push(await installLocale(locale));
+      } catch (err) {
+        lazy.logConsole.error(
+          `Could not install the search engine of ${extension.id}`,
+          err
+        );
+        revert = true;
+        break;
+      }
+    }
+    if (revert) {
+      for (let engine of engines) {
+        try {
+          this.removeEngine(engine);
+        } catch (err) {
+          lazy.logConsole.warn(
+            "Failed to revert the addition of a search engine",
+            err
+          );
+        }
+      }
     }
     return engines;
   }



View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/d11b0294d075b7034034a89513fc2fb105a9b883

-- 
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/d11b0294d075b7034034a89513fc2fb105a9b883
You're receiving this email because of your account on gitlab.torproject.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.torproject.org/pipermail/tbb-commits/attachments/20230816/ec6fb08f/attachment-0001.htm>


More information about the tbb-commits mailing list