Skip to content
Snippets Groups Projects
Commit 5d9e47cb authored by Dónal Murray's avatar Dónal Murray
Browse files

Deal with nullbyte terminated json properly on request side

parent 7c8fda57
Branches
No related merge requests found
......@@ -40,12 +40,8 @@ class HEVClient(object):
# grab data from the socket as soon as it is available and dump it in the db
while self._polling:
try:
data = b''
while True:
data += await reader.read(600)
if data[-1] == 0x00:
data = data[:-1]
break
data = await reader.readuntil(b'\0')
data = data[:-1] # snip off nullbyte
payload = json.loads(data.decode("utf-8"))
if payload["type"] == "keepalive":
#Still alive
......@@ -102,9 +98,8 @@ class HEVClient(object):
await writer.drain()
# wait for acknowledge
data = await reader.read(300)
if data[-1] == 0x00:
data = data[:-1]
data = await reader.read_until(b'\0')
data = data[:-1]
try:
data = json.loads(data.decode("utf-8"))
except json.decoder.JSONDecodeError:
......
......@@ -76,7 +76,8 @@ class HEVServer(object):
async def handle_request(self, reader: asyncio.StreamReader, writer: asyncio.StreamWriter) -> None:
# listen for queries on the request socket
data = await reader.read(300)
data = await reader.read_until(b'\0')
data = data[:-1] # snip off nullbyte
request = json.loads(data.decode("utf-8"))
# logging
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment