From 1b2bd2bdd5441fdb54c768030a2a80cc2c0da0d7 Mon Sep 17 00:00:00 2001 From: remittor Date: Thu, 7 Nov 2024 20:10:33 +0300 Subject: [PATCH] luci: Catch incorrect JSON into function decode_svc_info --- .../resources/view/zapret/tools.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/luci-app-zapret/htdocs/luci-static/resources/view/zapret/tools.js b/luci-app-zapret/htdocs/luci-static/resources/view/zapret/tools.js index b89b033..f578f71 100644 --- a/luci-app-zapret/htdocs/luci-static/resources/view/zapret/tools.js +++ b/luci-app-zapret/htdocs/luci-static/resources/view/zapret/tools.js @@ -160,10 +160,25 @@ return baseclass.extend({ } let plist = this.get_pid_list(proc_list.stdout); - let jdata = JSON.parse(svc_info.stdout); - if (typeof(jdata) !== 'object') { + if (plist.length < 4) { return -3; } + if (typeof(svc_info.stdout) !== 'string') { + return -4; + } + if (svc_info.stdout.length < 3) { + return -5; + } + let jdata; + try { + jdata = JSON.parse(svc_info.stdout); + } catch (e) { + console.log('Incorrect JSON: ' + svc_info.stdout); + return -6; + } + if (typeof(jdata) !== 'object') { + return -7; + } if (typeof(jdata.zapret) == 'object') { result.dmn.inited = true; let dmn_list = jdata.zapret.instances;