From 387bcd8a8b98fce03c9f347ade88519789ec42ca Mon Sep 17 00:00:00 2001 From: doronz Date: Sun, 5 Nov 2023 15:56:21 +0200 Subject: [PATCH] structs: fix unix sockaddr struct --- src/rpcclient/rpcclient/darwin/structs.py | 3 ++- src/rpcclient/rpcclient/structs/generic.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/rpcclient/rpcclient/darwin/structs.py b/src/rpcclient/rpcclient/darwin/structs.py index 8ac61d87..78d5b9af 100644 --- a/src/rpcclient/rpcclient/darwin/structs.py +++ b/src/rpcclient/rpcclient/darwin/structs.py @@ -485,7 +485,8 @@ def _encode(self, obj, context, path): # we can't use sockaddr_un since the sun_path may contain utf8 invalid characters sockaddr_un_raw = Struct( - 'sun_family' / Default(Int16sl, AF_UNIX), + 'sun_len' / Int8ul, + 'sun_family' / Default(Int8ul, AF_UNIX), '_sun_path' / Bytes(UNIX_PATH_MAX), 'sun_path' / Computed(lambda x: x._sun_path.split(b'\x00', 1)[0].decode()) ) diff --git a/src/rpcclient/rpcclient/structs/generic.py b/src/rpcclient/rpcclient/structs/generic.py index c8b9319b..7e1c75d4 100644 --- a/src/rpcclient/rpcclient/structs/generic.py +++ b/src/rpcclient/rpcclient/structs/generic.py @@ -3,7 +3,7 @@ from rpcclient.structs.consts import AF_INET, AF_INET6, AF_UNIX -UNIX_PATH_MAX = 108 +UNIX_PATH_MAX = 104 u_char = Int8ul uint8_t = Int8ul @@ -36,7 +36,8 @@ ) sockaddr_un = Struct( - 'sun_family' / Default(Int16sl, AF_UNIX), + 'sun_len' / Default(Int8ul, 0), + 'sun_family' / Default(Int8ul, AF_UNIX), 'sun_path' / PaddedString(UNIX_PATH_MAX, 'utf8'), )