Skip to content

Commit

Permalink
Fix client crashing bug on pty exit
Browse files Browse the repository at this point in the history
  • Loading branch information
cflems committed Jan 13, 2023
1 parent 9a9c7ff commit 352a8d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
1 change: 0 additions & 1 deletion pkcli_stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ def work(h_addr, port, privkey, bits):
if not run_pty(sock, screen_is, screen_os):
return True
screen_os.send(b'\xc0\xdenpty')
assert(screen_is.recv() == b'\xc0\xdeflush')
# TODO: this comes on time but the process zombifies after for some reason
continue
else:
Expand Down
18 changes: 8 additions & 10 deletions pkd_stub.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os, sys, socket, threading, signal, json, traceback
import os, sys, socket, threading, signal, json
from concurrent.futures import ThreadPoolExecutor

# initial crypto config
Expand Down Expand Up @@ -310,10 +310,6 @@ def unpty(client):
if not alive:
tcpc_lock.release()
return
try:
client['pty_os'].send(b'\xc0\xdeflush')
except:
client['alive'] = False
client['pty'] = False
del client['pty_is']
del client['pty_os']
Expand Down Expand Up @@ -367,13 +363,15 @@ def run_pty(screen, cn):
return False
except:
data = b'\xde\xad'
# TODO: problem is here: we wake up and suddenly not in pty mode
if not data or data == b'\xde\xad':
unpty(client)
return False
try:
pty_os.send(data)
except:
client['alive'] = False
elif alive and client['alive'] and client['pty'] == screen:
try:
pty_os.send(data)
except:
client['alive'] = False

def screen_reader(screen):
global alive, screens, screens_lock, cmdq, cmdq_lock, tcp_clients, tcpc_lock
Expand Down Expand Up @@ -540,7 +538,7 @@ def cleanup(*args):
if 'screen' in sockets:
sockets['screen'].close()
try:
ws = socket.socket(socket.AF_UNIX, sockte.SOCK_STREAM)
ws = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
ws.connect(socket_file)
ws.close()
except:
Expand Down

0 comments on commit 352a8d9

Please sign in to comment.