From 8c34d786e46adbcf5496549cb3fe1898761632d4 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Thu, 15 Aug 2019 09:52:38 +0200 Subject: Issue #1208: Fix jsonLoad in Sync's `util.js` to handle errors. - `OS.Path.join` can throw, so we always need to try/catch it. - Also do a sanity check to make sure `callback` is defined before use --- services/sync/modules/util.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'services/sync') diff --git a/services/sync/modules/util.js b/services/sync/modules/util.js index 7fd5a79716..73f4d8a801 100644 --- a/services/sync/modules/util.js +++ b/services/sync/modules/util.js @@ -321,10 +321,17 @@ this.Utils = { * could not be loaded, the first argument will be undefined. */ jsonLoad: Task.async(function*(filePath, that, callback) { - let path = OS.Path.join(OS.Constants.Path.profileDir, "weave", filePath + ".json"); + let path; + try { + path = OS.Path.normalize(OS.Path.join(OS.Constants.Path.profileDir, "weave", filePath + ".json")); + } catch (e) { + if (that._log) { + that._log.debug("Path join error: " + e); + } + } if (that._log) { - that._log.trace("Loading json from disk: " + filePath); + that._log.trace("Loading json from disk: " + path); } let json; @@ -341,8 +348,9 @@ this.Utils = { } } } - - callback.call(that, json); + if (callback) { + callback.call(that, json); + } }), /** -- cgit v1.2.3