snapdrop

A Progressive Web App for local file sharing
git clone http://git.hanabi.in/repos/snapdrop.git
Log | Files | Refs | README | LICENSE

commit 993b48439611a0594c2d6980ccad5172cb67560e
parent 72bb4cba1f4c744a95adb540041a1d16a1297cab
Author: RobinLinus <RobinLinus@users.noreply.github.com>
Date:   Wed, 29 May 2019 21:35:39 +0200

Don't crash when parsing malformed JSON
Diffstat:
Mserver/index.js | 12++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/server/index.js b/server/index.js @@ -26,8 +26,13 @@ class SnapdropServer { } _onMessage(sender, message) { - message = JSON.parse(message); - + // Try to parse message + try { + message = JSON.parse(message); + } catch (e) { + return; // TODO: handle malformed JSON + } + switch (message.type) { case 'disconnect': this._leaveRoom(sender); @@ -221,4 +226,4 @@ class Peer { }; } -const server = new SnapdropServer(process.env.PORT || 3000); -\ No newline at end of file +const server = new SnapdropServer(process.env.PORT || 3000);