Skip to content

macOS KVM: guard the IPC socket sinks against a stopped user LaunchAgent - #402

Open
PTR-inc wants to merge 1 commit into
Ylianst:masterfrom
PTR-inc:fix-mac-agent-crash-if-no-user-agent
Open

macOS KVM: guard the IPC socket sinks against a stopped user LaunchAgent#402
PTR-inc wants to merge 1 commit into
Ylianst:masterfrom
PTR-inc:fix-mac-agent-crash-if-no-user-agent

Conversation

@PTR-inc

@PTR-inc PTR-inc commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Summary

One of the test setups is running the root and user agent through terminal sessions, which showed the uncaught: 'cannot read property write of undefined' error after the user agent died and I tried to connect to the desktop.

What's happening is kvm_relay_setup() returns NULL when /tmp/meshagent-kvm-.sock is still on disk but the user agent is stopped, so nothing accepts on it. getRemoteDesktop() kept that NULL in ptrs->kvmPipe, and KVM_IPC_SOCKET is only set for the LoginWindow case, so the first desktop byte read "write" off undefined in the write sink. No protected call sits above a sink, so Duktape made it fatal and the root service exited 254 (ILIBCRITICALEXITMSG) with: uncaught: 'cannot read property write of undefined'

The pause and resume sinks had the same unguarded dereference.

Fixed by checking that KVM_IPC_SOCKET is an object in all three, return ILibTransport_DoneState_ERROR from the write sink, and report the failed connect to the MeshCentral console.

Details
  • 🧠 I used LLMs/AI in this contribution and reviewed all generated content.
    I understand that I am responsible for and able to explain every line of code I submit.
  • 🛠️ I have self-reviewed my code and self-tested it against a MeshCentral server to ensure it works as expected.
  • 🖥️ My change compiles on every platform it affects (Windows / Linux / macOS / FreeBSD), and I have considered
    the impact on platforms and architectures I could not test.
  • 📦 If I changed JavaScript modules under modules/, I re-embedded them so the compiled-in copies in
    microscript/ILibDuktape_Polyfills.c match (the agent runs the embedded copies, not the files on disk).
  • 🤖 I ran the agent self-test where appropriate (see "Self Test" in readme.md).
  • 📄 Documentation updates are included (if applicable), e.g. the .msh options table in readme.md.
  • 🧰 Updates to vendored dependencies (OpenSSL, zlib, ...) are listed and explained.
  • ⚠️ CI passes and is green (Windows / Linux / macOS / FreeBSD builds and CodeQL).

Testing

Tested on macos arm and x64

kvm_relay_setup() returns NULL when /tmp/meshagent-kvm-<uid>.sock is still on disk
but the user LaunchAgent is stopped, so nothing accepts on it.
getRemoteDesktop() kept that NULL in ptrs->kvmPipe, and KVM_IPC_SOCKET is only set for the LoginWindow case, so the first desktop byte read "write" off undefined in the write sink.
No protected call sits above a sink, so Duktape made it fatal and the root service
exited 254 (ILIBCRITICALEXITMSG) with: uncaught: 'cannot read property write of undefined'

The pause and resume sinks had the same unguarded dereference.

Check that KVM_IPC_SOCKET is an object in all three, return ILibTransport_DoneState_ERROR from
the write sink, and report the failed connect to the MeshCentral console.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant