[tor-commits] [Git][tpo/applications/tor-browser][tor-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:46 UTC 2023



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


Commits:
76d4d68d by Pier Angelo Vendrame at 2023-08-16T19:44:37+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
=====================================
@@ -2704,6 +2704,7 @@ export class SearchService {
     };
 
     let engines = [];
+    let revert = false;
     for (let locale of locales) {
       lazy.logConsole.debug(
         "addEnginesFromExtension: installing:",
@@ -2711,7 +2712,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/76d4d68dca9f9b64657ab3424b9324dfc88e8f2f

-- 
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/76d4d68dca9f9b64657ab3424b9324dfc88e8f2f
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/tor-commits/attachments/20230816/10ce5bbd/attachment-0001.htm>


More information about the tor-commits mailing list