From 0aae61f72e2f0ad3d7d3feaceb2d77b229e85510 Mon Sep 17 00:00:00 2001 From: Caleb James DeLisle Date: Tue, 12 Dec 2017 14:18:22 +0100 Subject: [PATCH] Anonymous RPC GET_FILE_SIZE does not work correctly unless at least one authenticated RPC has been called first. Also RPC failures (throw error) are silent in the logs --- rpc.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/rpc.js b/rpc.js index a4821524b..410e5f22b 100644 --- a/rpc.js +++ b/rpc.js @@ -1057,11 +1057,9 @@ RPC.create = function (config /*:typeof(ConfigType)*/, cb /*:(?Error, ?Function) } }; - var rpc = function ( - ctx /*:{ store: Object }*/, - data /*:Array>*/, - respond /*:(?string, ?Array)=>void*/) - { + var rpc0 = function (ctx, data, respond) { + if (!Env.msgStore) { Env.msgStore = ctx.store; } + if (!Array.isArray(data)) { return void respond('INVALID_ARG_FORMAT'); } @@ -1140,8 +1138,6 @@ RPC.create = function (config /*:typeof(ConfigType)*/, cb /*:(?Error, ?Function) Respond('E_ACCESS_DENIED'); }; - if (!Env.msgStore) { Env.msgStore = ctx.store; } - var handleMessage = function (privileged) { if (config.logRPC) { console.log(msg[0]); } switch (msg[0]) { @@ -1272,6 +1268,19 @@ RPC.create = function (config /*:typeof(ConfigType)*/, cb /*:(?Error, ?Function) handleMessage(session.privilege); }; + var rpc = function ( + ctx /*:{ store: Object }*/, + data /*:Array>*/, + respond /*:(?string, ?Array)=>void*/) + { + try { + return rpc0(ctx, data, respond); + } catch (e) { + console.log("Error from RPC with data " + JSON.stringify(data)); + console.log(e.stack); + } + }; + var updateLimitDaily = function () { updateLimits(config, undefined, function (e) { if (e) {