Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UDP Port out of range: -7915 #7

Closed
pimterry opened this issue Oct 24, 2019 · 4 comments

Comments

@pimterry
Copy link

@pimterry pimterry commented Oct 24, 2019

Hi, I'm building an app that uses some of the VPN logic from this codebase (https://github.com/httptoolkit/httptoolkit-android), and I've been seeing this error intermittently. The error looks like this:

    java.lang.IllegalArgumentException: port out of range:-7915
        at java.net.InetSocketAddress.checkPort(InetSocketAddress.java:144)
        at java.net.InetSocketAddress.<init>(InetSocketAddress.java:239)
        at com.lipisoft.toyshark.SessionManager.createNewUDPSession(SessionManager.java:199)
        at com.lipisoft.toyshark.SessionHandler.handleUDPPacket(SessionHandler.java:65)
        at com.lipisoft.toyshark.SessionHandler.handlePacket(SessionHandler.java:195)

The error is always the same port: -7915, and it's always a UDP packet. I've made some small changes, but only related to TCP, so I don't think they're related.

Any ideas what might cause this? I can simply drop those packets myself for now, but it would be nice to know why its happening and maybe fix the issue properly. Any clues would be very helpful!

@pimterry

This comment has been minimized.

Copy link
Author

@pimterry pimterry commented Oct 24, 2019

Ah, I've found it! -7915 converted from a signed short to an unsigned short is 57621. That's the UDP port used by Spotify to communicate with networked clients (and Spotify is indeed running on this phone right now).

That suggests that somewhere here we're decoding UDP ports as signed shorts instead of unsigned, so any UDP requests to ports above 32767 will crash the VPN.

I'll dig into it and let you know once I find the problem.

@pimterry

This comment has been minimized.

Copy link
Author

@pimterry pimterry commented Oct 24, 2019

All done, the fix is here: httptoolkit/httptoolkit-android@59fee53

I can't easily directly PR it, since I'm just wrapping some of the code here rather than fully forking the app, but you should be able to apply the above directly fairly easily.

Thanks for this project by the way, it's been super useful in getting my VPN set up and transparently forwarding properly 👍.

@pimterry pimterry closed this Oct 24, 2019
@LipiLee

This comment has been minimized.

Copy link
Owner

@LipiLee LipiLee commented Oct 29, 2019

Thanks for your report and fix. I will apply it.

@pimterry

This comment has been minimized.

Copy link
Author

@pimterry pimterry commented Oct 29, 2019

No problem @LipiLee, hope it's useful!

You might also be interested in httptoolkit/httptoolkit-android@f961bda. Right now, this code loops very intensely in SocketNIODataService, which uses a lot of CPU & battery. It doesn't need to: that commit makes sure it always waits for new data to send or receive before waking up, and fixes a couple of potential race conditions around selection keys too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.