Timac / VPNStatus

VPNStatus, a replacement for macOS builtin VPN Status
https://blog.timac.org/2018/0719-vpnstatus/
MIT License
221 stars 31 forks source link

ne_session_set_event_handler_block prototype #17

Closed alxtplv closed 2 years ago

alxtplv commented 2 years ago

Debug version of VPNStatus.app crashes on [ACNEService setupEventCallback]_block_invoke when running on my M1 Apple Silicon. (XCode 13.2.1, MacOS 12.2.1) M1 release version, and Intel/Rosetta versions work fine, though.

ACDefines.h, line 49 typedef void (^ne_session_set_event_handler_block)(xpc_object_t result);

Perhaps it should be typedef void (^ne_session_set_event_handler_block)(ne_session_event_t event, void *event_data);

Timac commented 2 years ago

Thanks for reporting this weird issue. Could you please run image list in lldb when debugging VPNStatus? At the moment I have no explanation explaining that this issue only occurs for debug builds on M1 machines. Could it be that /usr/lib/system/libsystem_networkextension.dylib is not used on your machine but instead another debug dylib which doesn't know about ne_session_set_event_handler_block?

alxtplv commented 2 years ago

While debugging arm64 version:

(lldb) image list | grep libsystem_networkextension.dylib [ 0] B9F72E76-4B73-3B63-89E0-9D359BFDE954 0x00000001ba6ee000 /usr/lib/system/libsystem_networkextension.dylib

With ne_session_set_event_handler_block changed to typedef void (^ne_session_set_event_handler_block)(ne_session_event_t event, void *event_data); and defined typedef int ne_session_event_t; both arm64 VPNStatus builds (debug and release ) work fine on my M1. X86_64 builds work fine under Rosetta as well.

SCNetworkConnection.c, line 2468 ne_session_set_event_handler(connectionPrivate->ne_session, __SCNetworkConnectionQueue(), ^(ne_session_event_t event, void *event_data) ...

line 2746 ne_session_set_event_handler(new_session, __SCNetworkConnectionQueue(), ^(ne_session_event_t event, void *event_data) ...

Timac commented 2 years ago

@alxtplv Thanks a lot for the research and help. It appears that you are absolutely right and I incorrectly reverse-engineered the prototype of ne_session_set_event_handler_block. I modified the code as you suggested.

The fact that the parameters were not used might explain why the release version was not crashing?