Add null-byte after size bytes
This commit is contained in:
parent
46a32f2255
commit
4cea08c314
@ -62,12 +62,15 @@ def removeThread():
|
|||||||
tprint(colorama.Fore.YELLOW + colorama.Style.BRIGHT + "Thread closed. Threads: " +str(threadCount)+ " (Actual: " +str(threading.active_count())+ ")" + colorama.Style.RESET_ALL)
|
tprint(colorama.Fore.YELLOW + colorama.Style.BRIGHT + "Thread closed. Threads: " +str(threadCount)+ " (Actual: " +str(threading.active_count())+ ")" + colorama.Style.RESET_ALL)
|
||||||
|
|
||||||
def sendResponse(connection,data):
|
def sendResponse(connection,data):
|
||||||
connection.sendall(len(data).to_bytes(4,"big") + data)
|
connection.sendall(len(data).to_bytes(4,"big") + b"\x00" + data)
|
||||||
|
|
||||||
def getResponse(connection):
|
def getResponse(connection):
|
||||||
data = b''
|
data = b''
|
||||||
data = connection.recv(4)
|
data = connection.recv(4)
|
||||||
if not data: return False
|
if not data: return False
|
||||||
|
nul = connection.recv(1)
|
||||||
|
if not nul: return False
|
||||||
|
if nul != b"\x00": return False
|
||||||
requestLength = int.from_bytes(data,"big")
|
requestLength = int.from_bytes(data,"big")
|
||||||
if requestLength > maxRequestSize: raise Exception("security","request_too_large")
|
if requestLength > maxRequestSize: raise Exception("security","request_too_large")
|
||||||
return connection.recv(requestLength)
|
return connection.recv(requestLength)
|
||||||
|
@ -32,7 +32,7 @@ class receiverThread(threading.Thread):
|
|||||||
print("server: " +response)
|
print("server: " +response)
|
||||||
|
|
||||||
def sendRequest(connection,data):
|
def sendRequest(connection,data):
|
||||||
connection.sendall(len(data).to_bytes(4,"big") + data)
|
connection.sendall(len(data).to_bytes(4,"big") + b"\x00" + data)
|
||||||
|
|
||||||
def getResponse(connection):
|
def getResponse(connection):
|
||||||
data = b''
|
data = b''
|
||||||
@ -42,6 +42,15 @@ def getResponse(connection):
|
|||||||
connection.close()
|
connection.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
nul = connection.recv(1)
|
||||||
|
if not nul:
|
||||||
|
connection.close()
|
||||||
|
return
|
||||||
|
|
||||||
|
if nul != b"\x00":
|
||||||
|
connection.close()
|
||||||
|
return
|
||||||
|
|
||||||
requestLength = int.from_bytes(data,"big")
|
requestLength = int.from_bytes(data,"big")
|
||||||
data = connection.recv(requestLength)
|
data = connection.recv(requestLength)
|
||||||
return data
|
return data
|
||||||
|
Loading…
Reference in New Issue
Block a user