Skip to content

fix: prevent nil dereference when VLESS listener initialization fails - #3195

Merged
wwqgtxx merged 1 commit into
MetaCubeX:Alphafrom
truimo-dev:fix/vless-decryption-cleanup
Sep 9, 2026
Merged

fix: prevent nil dereference when VLESS listener initialization fails#3195
wwqgtxx merged 1 commit into
MetaCubeX:Alphafrom
truimo-dev:fix/vless-decryption-cleanup

Conversation

@Truimo

@Truimo Truimo commented Sep 9, 2026

Copy link
Copy Markdown

Summary

Fix a nil pointer dereference in the VLESS listener when decryption is enabled and a later initialization step fails.

Cause

listener/sing_vless.New uses named return values:

func New(...) (sl *Listener, err error)

After initializing the decryption instance, it registers a deferred cleanup function:

defer func() {
    if err != nil {
        _ = sl.decryption.Close()
    }
}()

If a later initialization step fails, such as certificate path validation or port binding, the function returns:

return nil, err

The named return value sl is set to nil before the deferred function runs. The deferred cleanup then dereferences
sl.decryption, causing:

panic: runtime error: invalid memory address or nil pointer dereference

This masks the original initialization error.

Fix

Capture the decryption pointer in a local variable before registering the deferred cleanup:

decryption := sl.decryption
defer func() {
    if err != nil {
        _ = decryption.Close()
    }
}()

This ensures that the decryption instance is closed safely and that the original initialization error is returned to the
caller.

Expected Behavior

For example, when the certificate path is not included in the allowed paths, Mihomo should return the original error:

parse certificate failed, maybe format error:
tls: failed to find any PEM data in certificate input,
or path error: path is not subpath of home directory or SAFE_PATHS

It should not panic with a nil pointer dereference.

@wwqgtxx
wwqgtxx merged commit 20bcda2 into MetaCubeX:Alpha Sep 9, 2026
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.

2 participants