proj: Adapt test scripts and fix bugs
This commit is contained in:
4
Makefile
4
Makefile
@@ -1,7 +1,7 @@
|
|||||||
.PHONY: all clean
|
.PHONY: all clean
|
||||||
all:
|
all:
|
||||||
$(MAKE) -C proj/test1/
|
$(MAKE) -C proj/test1/
|
||||||
$(MAKE) -C proj/test2/ -C /usr/src/linux-`uname -r` SUBDIRS=$PWD modules
|
$(MAKE) -C proj/intercept/
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -C proj/test1/
|
$(MAKE) -C proj/test1/
|
||||||
$(MAKE) -C proj/test2/
|
$(MAKE) -C proj/intercept/
|
||||||
|
|||||||
@@ -2225,7 +2225,11 @@ int sym(getaddrinfo)(const char *restrict node, const char *restrict service, co
|
|||||||
else if_invalid(getaddrinfo)
|
else if_invalid(getaddrinfo)
|
||||||
}
|
}
|
||||||
const int ret = __real_getaddrinfo(node, service, hints, res);
|
const int ret = __real_getaddrinfo(node, service, hints, res);
|
||||||
msg("return %i; errno %s", ret, strerrorname_np(errno));
|
if (res != NULL) {
|
||||||
|
msg("return %i; errno %s; res=%p", ret, strerrorname_np(errno), *res);
|
||||||
|
} else {
|
||||||
|
msg("return %i; errno %s", ret, strerrorname_np(errno), *res);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,12 +61,12 @@ class Handler(StreamRequestHandler):
|
|||||||
self.after()
|
self.after()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_str(argument: str) -> tuple[str or bytes, int]:
|
def parse_str(argument: str) -> tuple[bytes, int]:
|
||||||
if not ((len(argument) >= 2 and argument[0] == '"') or (len(argument) >= 3 and argument[0] == 'b' and argument[1] == '"')):
|
if not (len(argument) >= 2 and argument[0] == '"'):
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
idx = 1
|
idx = 1
|
||||||
esc, fin = False, False
|
esc, fin = False, False
|
||||||
data = b'' if argument[0] == 'b' else ''
|
data = b''
|
||||||
tmp = None
|
tmp = None
|
||||||
for ch in argument[1:]:
|
for ch in argument[1:]:
|
||||||
idx += 1
|
idx += 1
|
||||||
@@ -79,22 +79,26 @@ class Handler(StreamRequestHandler):
|
|||||||
elif tmp:
|
elif tmp:
|
||||||
tmp += ch
|
tmp += ch
|
||||||
if len(tmp) == 2:
|
if len(tmp) == 2:
|
||||||
data += bytes([int(tmp, 16)]) if argument[0] == 'b' else chr(int(tmp, 16))
|
data += bytes([int(tmp, 16)])
|
||||||
tmp = None
|
tmp = None
|
||||||
elif esc:
|
elif esc:
|
||||||
if ch in ('\\', '"'):
|
if ch in ('\\', '"'):
|
||||||
data += ch.encode('ascii') if argument[0] == 'b' else ch
|
data += ch.encode('ascii')
|
||||||
|
esc = False
|
||||||
elif ch == 'x':
|
elif ch == 'x':
|
||||||
tmp = ''
|
tmp = ''
|
||||||
esc = False
|
esc = False
|
||||||
|
elif ch in ('n', 'r'):
|
||||||
|
data += b'\n' if ch == 'n' else b'\r'
|
||||||
|
esc = False
|
||||||
else:
|
else:
|
||||||
raise ValueError()
|
raise ValueError(ch)
|
||||||
elif ch == '"':
|
elif ch == '"':
|
||||||
fin = True
|
fin = True
|
||||||
elif ch == '\\':
|
elif ch == '\\':
|
||||||
esc = True
|
esc = True
|
||||||
else:
|
else:
|
||||||
data += ch.encode('utf-8') if argument[0] == 'b' else ch
|
data += ch.encode('utf-8')
|
||||||
if not fin:
|
if not fin:
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
return data, idx
|
return data, idx
|
||||||
@@ -106,6 +110,14 @@ class Handler(StreamRequestHandler):
|
|||||||
m = re.match(r'^\s*(\(nil\)|NULL|null|nullptr)\s*(,|$)', argument)
|
m = re.match(r'^\s*(\(nil\)|NULL|null|nullptr)\s*(,|$)', argument)
|
||||||
if m:
|
if m:
|
||||||
return 0, len(m.group(0))
|
return 0, len(m.group(0))
|
||||||
|
m = re.match(r'\s*"', argument)
|
||||||
|
if m:
|
||||||
|
idx = len(m.group(0)) - 1
|
||||||
|
s, i = Handler.parse_str(argument[idx:])
|
||||||
|
idx = i
|
||||||
|
if idx < len(argument) and argument[idx] == ',':
|
||||||
|
idx += 1
|
||||||
|
return s, idx
|
||||||
m = re.match(r'^\s*(.*?)([,:]|$)', argument)
|
m = re.match(r'^\s*(.*?)([,:]|$)', argument)
|
||||||
a, e = m.group(1), m.group(2)
|
a, e = m.group(1), m.group(2)
|
||||||
idx = len(m.group(0))
|
idx = len(m.group(0))
|
||||||
@@ -141,20 +153,27 @@ class Handler(StreamRequestHandler):
|
|||||||
idx += 1
|
idx += 1
|
||||||
return (val, s), idx
|
return (val, s), idx
|
||||||
elif argument[idx] == '{':
|
elif argument[idx] == '{':
|
||||||
m = re.match(r'^[^}]*', argument[idx:])
|
m = re.match(r'^[^}]*}', argument[idx:])
|
||||||
value = m.group(0)
|
if not m or not m.group(0).startswith('{') or not m.group(0).endswith('}'):
|
||||||
if not value.startswith('{') or not value.endswith('}'):
|
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
|
value = m.group(0)
|
||||||
idx += len(value)
|
idx += len(value)
|
||||||
if idx < len(argument) and argument[idx] == ',':
|
if idx < len(argument) and argument[idx] == ',':
|
||||||
idx += 1
|
idx += 1
|
||||||
entries = {}
|
entries = {}
|
||||||
for e in [v.strip() for v in value[1:-1].split(',') if len(e.strip()) > 0]:
|
for e in [v.strip() for v in value[1:-1].split(',') if len(v.strip()) > 0]:
|
||||||
k, v = e.split(':', 1)
|
k, v = e.split(':', 1)
|
||||||
entries[k.strip()] = int(v.strip(), 0)
|
entries[k.strip()] = Handler.parse_arg(v)[0]
|
||||||
return (val, entries), idx
|
return (val, entries), idx
|
||||||
else:
|
else:
|
||||||
raise ValueError()
|
m = re.match(r'[A-Z0-9_]+', argument[idx:])
|
||||||
|
if not m:
|
||||||
|
raise ValueError()
|
||||||
|
value = m.group(0)
|
||||||
|
idx += len(value)
|
||||||
|
if idx < len(argument) and argument[idx] == ',':
|
||||||
|
idx += 1
|
||||||
|
return (val, value), idx
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_args(arguments: str) -> tuple[tuple, int]:
|
def parse_args(arguments: str) -> tuple[tuple, int]:
|
||||||
@@ -201,7 +220,8 @@ class Handler(StreamRequestHandler):
|
|||||||
self.wfile.write(command.encode('utf-8') + b'\n')
|
self.wfile.write(command.encode('utf-8') + b'\n')
|
||||||
else:
|
else:
|
||||||
ret = data.decode('utf-8')
|
ret = data.decode('utf-8')
|
||||||
ret_value, _ = Handler.parse_arg(ret[7:].split(';')[0])
|
ret_value, _ = Handler.parse_arg(ret[7:].split(';', 1)[0])
|
||||||
|
# FIXME parse return values (errno, ...)
|
||||||
(self.ret_addr, self.dli_file_name, self.rel_ret_addr, self.dli_sym_name, func_name, args) = self.stack.pop()
|
(self.ret_addr, self.dli_file_name, self.rel_ret_addr, self.dli_sym_name, func_name, args) = self.stack.pop()
|
||||||
try:
|
try:
|
||||||
func = getattr(self, f'after_{func_name}')
|
func = getattr(self, f'after_{func_name}')
|
||||||
@@ -461,10 +481,10 @@ class Handler(StreamRequestHandler):
|
|||||||
def after_connect(self, sockfd: int, address: PointerTo[StructSockAddr], address_len: int,
|
def after_connect(self, sockfd: int, address: PointerTo[StructSockAddr], address_len: int,
|
||||||
ret_value: int, errno: str = None) -> None:
|
ret_value: int, errno: str = None) -> None:
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
def before_getaddrinfo(self, node: PointerTo[bytes], service: PointerTo[bytes], hints: PointerTo[StructAddrInfo], res: Pointer) -> str:
|
def before_getaddrinfo(self, node: PointerTo[bytes], service: PointerTo[bytes], hints: PointerTo[StructAddrInfo], res_ptr: Pointer) -> str:
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
def after_getaddrinfo(self, node: PointerTo[bytes], service: PointerTo[bytes], hints: PointerTo[StructAddrInfo], res: Pointer,
|
def after_getaddrinfo(self, node: PointerTo[bytes], service: PointerTo[bytes], hints: PointerTo[StructAddrInfo], res_ptr: Pointer,
|
||||||
ret_value: int, errno: str = None) -> None:
|
ret_value: int, errno: str = None, res: Pointer = None) -> None:
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
def before_freeaddrinfo(self, res: Pointer) -> str:
|
def before_freeaddrinfo(self, res: Pointer) -> str:
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ def main() -> None:
|
|||||||
subprocess.run(extra, env={
|
subprocess.run(extra, env={
|
||||||
'LD_PRELOAD': os.getcwd() + '/../../intercept/intercept.so',
|
'LD_PRELOAD': os.getcwd() + '/../../intercept/intercept.so',
|
||||||
'INTERCEPT': 'unix:' + socket_name,
|
'INTERCEPT': 'unix:' + socket_name,
|
||||||
'INTERCEPT_FUNCTIONS': ','.join(['*', '-malloc', '-calloc', '-realloc', '-reallocarray', '-free']),
|
'INTERCEPT_FUNCTIONS': '*',
|
||||||
|
'INTERCEPT_LIBRARIES': '*,-/lib*,-/usr/lib*',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ def main() -> None:
|
|||||||
subprocess.run(extra, env={
|
subprocess.run(extra, env={
|
||||||
'LD_PRELOAD': os.getcwd() + '/../../intercept/intercept.so',
|
'LD_PRELOAD': os.getcwd() + '/../../intercept/intercept.so',
|
||||||
'INTERCEPT': 'unix:' + socket_name,
|
'INTERCEPT': 'unix:' + socket_name,
|
||||||
'INTERCEPT_FUNCTIONS': ','.join(['malloc', 'calloc', 'realloc', 'reallocarray', 'free']),
|
'INTERCEPT_FUNCTIONS': ','.join(['malloc', 'calloc', 'realloc', 'reallocarray', 'free', 'getaddrinfo', 'freeaddrinfo']),
|
||||||
|
'INTERCEPT_LIBRARIES': '*,-/lib*,-/usr/lib*',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ def main() -> None:
|
|||||||
subprocess.run(extra, stdin=stdin, env={
|
subprocess.run(extra, stdin=stdin, env={
|
||||||
'LD_PRELOAD': os.getcwd() + '/../../intercept/intercept.so',
|
'LD_PRELOAD': os.getcwd() + '/../../intercept/intercept.so',
|
||||||
'INTERCEPT': 'unix:' + socket_name,
|
'INTERCEPT': 'unix:' + socket_name,
|
||||||
'INTERCEPT_FUNCTIONS': ','.join(['*', '-malloc', '-calloc', '-realloc', '-reallocarray', '-free']),
|
'INTERCEPT_FUNCTIONS': '*',
|
||||||
|
'INTERCEPT_LIBRARIES': '*,-/lib*,-/usr/lib*',
|
||||||
})
|
})
|
||||||
for i, name in enumerate(ctx['call_sequence']):
|
for i, name in enumerate(ctx['call_sequence']):
|
||||||
errors = [r[1] for r in ctx['results'] if r[0] == i]
|
errors = [r[1] for r in ctx['results'] if r[0] == i]
|
||||||
|
|||||||
Reference in New Issue
Block a user