From: Ian Jackson Date: Wed, 18 Oct 2017 23:49:38 +0000 (+0100) Subject: fishdescriptor: bugfixes X-Git-Tag: archive/debian/6.0.0~1^2~26 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-utils.git;a=commitdiff_plain;h=c4df1b1d1d9422c2ea94a9c0bc7801ac2c4678ed fishdescriptor: bugfixes Signed-off-by: Ian Jackson --- diff --git a/fishdescriptor/fishdescriptor b/fishdescriptor/fishdescriptor index 4708401..7150df2 100755 --- a/fishdescriptor/fishdescriptor +++ b/fishdescriptor/fishdescriptor @@ -4,7 +4,7 @@ import sys import fishdescriptor.fish pid = int(sys.argv[1]) -fds = map(int, sys.argv[2:]) +fds = [int(x) for x in sys.argv[2:]] d = fishdescriptor.fish.Donor(pid) r = d.fish(fds) diff --git a/fishdescriptor/py/fishdescriptor/fish.py b/fishdescriptor/py/fishdescriptor/fish.py index 4739feb..78bb2d8 100644 --- a/fishdescriptor/py/fishdescriptor/fish.py +++ b/fishdescriptor/py/fishdescriptor/fish.py @@ -50,7 +50,7 @@ class Donor(): ap = subprocess.Popen( stdin = subprocess.DEVNULL, stdout = subprocess.PIPE, - args = ['perl','-we',perl_script] + fds + args = ['perl','-we',perl_script] + [str(x) for x in fds] ) (output, dummy) = ap.communicate() return output @@ -76,11 +76,11 @@ class Donor(): def _sock_dir(d, target_euid): run_dir = '/run/user/%d' % target_euid if d._exists(run_dir): - return run_dir + 'fishdescriptor' + return run_dir + '/fishdescriptor' try: pw = pwd.getpwuid(target_euid) - return pw.pw_dir + '.fishdescriptor' + return pw.pw_dir + '/.fishdescriptor' except KeyError: pass @@ -98,7 +98,7 @@ class Donor(): sockname = '%s/%s,%d' % (sockdir, os.uname().nodename, d._pid) - target_root = '/proc/%d/root/' % d._pid + target_root = '/proc/%d/root' % d._pid if not d._exists(target_root): target_root = '' diff --git a/fishdescriptor/py/fishdescriptor/indonor.py b/fishdescriptor/py/fishdescriptor/indonor.py index 12f8c68..fe0b78d 100644 --- a/fishdescriptor/py/fishdescriptor/indonor.py +++ b/fishdescriptor/py/fishdescriptor/indonor.py @@ -5,10 +5,17 @@ import gdb import copy import os import sys +import socket + +def _string_bytearray(s): + # gets us bytes in py2 and py3 + if not isinstance(s, bytes): + s = s.encode('utf-8') # sigh, python 2/3 compat + return bytearray(s) def _string_escape_for_c(s): out = '' - for c in bytearray(s): # gets us bytes in py2 and py3 + for c in _string_bytearray(s): if c == ord('\\') or c == ord('"') or c < 32 or c > 126: out += '\\x%02x' % c else: @@ -24,10 +31,8 @@ def _lit_aggregate_uncasted(val_lit_strs): return '{' + ', '.join(['(%s)' % v for v in val_lit_strs]) + ' }' def _lit_string_uncasted(s): - if not isinstance(s, bytes): - s = s.encode('utf-8') # sigh, python 2/3 compat - b = bytearray(s) - return _lit_aggregate_uncasted(map(_lit_integer, b) + [ '0' ]) + b = _string_bytearray(s) + return _lit_aggregate_uncasted([_lit_integer(x) for x in b] + [ '0' ]) def _lit_array(elemtype, val_lit_strs): return ( @@ -59,9 +64,12 @@ class DonorStructLayout(): l._posns = { } for f in x.type.fields(): l._posns[f.name] = len(l._template) - try: f.type.fields(); blank = '{ }' + try: f.type.fields(); blank = '{ }' + except TypeError: blank = '0' except AttributeError: blank = '0' l._template.append(blank) + sys.stderr.write('## STRUCT %s template %s fields %s\n' + % (typename, l._template, l._posns)) def substitute(l, values): build = copy.deepcopy(l._template) @@ -77,15 +85,15 @@ class DonorImplementation(): # assembling structs # sigh, we have to record the order of the arguments! - def _find_fields(typename): + def _find_fields(di, typename): try: fields = di._structs[typename] - except AttributeError: + except KeyError: fields = DonorStructLayout(typename) di._structs[typename] = fields return fields - def _make(typename, values): + def _make(di, typename, values): fields = di._find_fields(typename) return fields.substitute(values) @@ -107,7 +115,7 @@ class DonorImplementation(): # wrappers for the syscalls that do what we want def _sendmsg(di, carrier, control_msg): - iov_base = _lit_array('int', map(str,fds)) + iov_base = _lit_array('int', [str(x) for x in fds]) iov = di._make('struct iovec', { 'iov_base': iov_base, 'iov_len' : len(fds),