Fix panic when remote forward target is unavailable#355
Merged
antoniomika merged 1 commit intoantoniomika:mainfrom Oct 7, 2025
Merged
Fix panic when remote forward target is unavailable#355antoniomika merged 1 commit intoantoniomika:mainfrom
antoniomika merged 1 commit intoantoniomika:mainfrom
Conversation
Owner
|
Thanks for the contribution @pilat! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi Antonio Mika 👋
Thanks for building and maintaining sish — it's been really useful.
This PR fixes a crash that occurs when a client creates a remote forward pointing to a local service that isn't listening. In that case
OpenChannel("forwarded-tcpip", ...)fails and returns anilchannel; we then pass thatnilchannel intoutils.CopyBoth, which leads to a nil-pointer dereference.Reproduction
First window — run sish:
go run . \ -a 127.0.0.1:2222 \ -i 127.0.0.1:8080 \ --authentication=false \ --bind-any-host=true \ --domain=sish.test \ --bind-random-subdomains=false \ --debugSecond window – request a remote forward to a non-existent local service (port
8765is not bound):Third window – hit the route:
curl -v http://127.0.0.1:8080/ -H "Host: some-host.sish.test"Panic
Root cause
When the remote-forward destination is down or unbound, this call:
returns
newChan == nilanderr != nil. We logged the error, closedcl, but continued to the I/O copy path, eventually invokingutils.CopyBoth(cl, newChan)with a nil reader.Fix
Add an early return on
OpenChannelerror to avoid usingnewChanwhen it's nil and to closecl:Nothing else in the flow changes. The connection now fails gracefully.
Behavior after the fix
With this change, the application no longer crashes when a remote forward target is unavailable.
Verification
Verified manually by repeating the same scenario described above. The panic no longer occurs and the server stays stable.
Let me know if you'd like any additional adjustments or if the change conflicts with other parts of the codebase.