Bug 1552004 - dont' use "eval" in the OTR code. r=mkmelin
Differential Revision: https://phabricator.services.mozilla.com/D32839
This commit is contained in:
Родитель
ed216ba883
Коммит
e0f08d4ab3
|
@ -8,9 +8,7 @@ var PromiseWorker = require("resource://gre/modules/workers/PromiseWorker.js");
|
|||
var Funcs = {};
|
||||
|
||||
// Only what we need from libotr.js
|
||||
Funcs.generateKey = function(path, otrl_version, newkeySource) {
|
||||
// eslint-disable-next-line no-eval
|
||||
let newkey = eval(newkeySource); // jshint ignore:line
|
||||
Funcs.generateKey = function(path, otrl_version, address) {
|
||||
let libotr = ctypes.open(path);
|
||||
|
||||
let abi = ctypes.default_abi;
|
||||
|
@ -31,6 +29,8 @@ Funcs.generateKey = function(path, otrl_version, newkeySource) {
|
|||
);
|
||||
|
||||
otrl_init.apply(libotr, otrl_version);
|
||||
|
||||
let newkey = ctypes.voidptr_t(ctypes.UInt64("0x" + address));
|
||||
let err = otrl_privkey_generate_calculate(newkey);
|
||||
libotr.close();
|
||||
if (err)
|
||||
|
|
|
@ -182,9 +182,24 @@ var OTR = {
|
|||
);
|
||||
if (err || newkey.isNull())
|
||||
return Promise.reject("otrl_privkey_generate_start (" + err + ")");
|
||||
|
||||
let keyPtrSrc = newkey.toSource();
|
||||
let re = new RegExp(
|
||||
"^ctypes\\.voidptr_t\\(ctypes\\.UInt64\\(\"0x([0-9a-fA-F]+)\"\\)\\)$");
|
||||
let address;
|
||||
let match = re.exec(keyPtrSrc);
|
||||
if (match) {
|
||||
address = match[1];
|
||||
}
|
||||
|
||||
if (!address) {
|
||||
OTRLib.otrl_privkey_generate_cancelled(OTR.userstate, newkey);
|
||||
throw new Error("generatePrivateKey failed to parse ptr.toSource(): " + keyPtrSrc);
|
||||
}
|
||||
|
||||
let worker = new BasePromiseWorker(workerPath);
|
||||
return worker.post("generateKey", [
|
||||
OTRLib.path, OTRLib.otrl_version, newkey.toSource(),
|
||||
OTRLib.path, OTRLib.otrl_version, address,
|
||||
]).then(function() {
|
||||
let err = OTRLib.otrl_privkey_generate_finish(
|
||||
OTR.userstate, newkey, OTR.privateKeyPath
|
||||
|
|
Загрузка…
Ссылка в новой задаче