snapcast
snapcast copied to clipboard
Malformed JSON can crash server
Describe the bug An empty JSON message crashed snapserver.
Steps to Reproduce
- Send a message that should contain JSON, for example a Hello message, but that has length 0. e.g. i accedently send this one which has 0 as a payload size in the hello part:
\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xdc\x00\x00\x00\x00\x00\x00\x00{"Arch": "x86_64", "ClientName": "Snapclient", "HostName": "my_hostname", "ID": "00:11:22:33:44:55", "Instance": 1, "MAC": "00:11:22:33:44:55", "OS": "Arch Linux", "SnapStreamProtocolVersion": 2, "Version": "0.17.1"}
- Snapserver crashes
Environment details
- OS: debian
- Snapcast version c0.26.0
- Installed from AUR
Attach logfile if applicable
snapserver --logging.filter debug
:
2022-09-08 16-19-12.115 [Notice] (StreamServer) StreamServer::NewConnection: 127.0.0.1
2022-09-08 16-19-12.115 [Debug] (StreamSessionTCP) getNextMessage: Hello, size: 220, id: 0, refers: 0
2022-09-08 16-19-12.115 [Debug] (Server) onMessageReceived: Hello, size: 220, id: 0, refers: 0, sent: 0,0, recv: 17345,333810
2022-09-08 16-19-12.115 [Debug] (StreamSessionTCP) ~StreamSessionTcp
2022-09-08 16-19-12.115 [Debug] (StreamSessionTCP) stop
2022-09-08 16-19-12.115 [Debug] (StreamSessionTCP) stopped
terminate called after throwing an instance of 'nlohmann::detail::parse_error'
what(): [json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal
[1] 36593 IOT instruction (core dumped) snapserver --logging.filter debug
Should be fixed in develop branch 0da026a2895907f2d58ca0d103addd4ac80e339e. Can you please test it?