fix: bounds-check the IPC result before accessing. (#24041)

* fix: bounds-check the IPC result before accessing.

* fix: address feedback about safety checking JS too

* fix: address feedback: check JS array length, too.
This commit is contained in:
Charles Kerr
2020-06-11 11:47:58 -05:00
committed by GitHub
parent 4fb7b33b2b
commit cbaaf6a34e
2 changed files with 9 additions and 1 deletions

View File

@@ -13,7 +13,11 @@ if (!ipcRenderer.send) {
};
ipcRenderer.sendSync = function (channel, ...args) {
return ipc.sendSync(internal, channel, args)[0];
const result = ipc.sendSync(internal, channel, args);
if (!Array.isArray(result) || result.length !== 1) {
throw new Error(`Unexpected return value from ipcRenderer.sendSync: ${result}`);
}
return result[0];
};
ipcRenderer.sendToHost = function (channel, ...args) {

View File

@@ -102,6 +102,10 @@ class IPCRenderer : public mate::Wrappable<IPCRenderer> {
electron_browser_ptr_->MessageSync(internal, channel, std::move(arguments),
&result);
if (!result.is_list() || result.GetList().empty())
return base::Value{};
return std::move(result.GetList().at(0));
}