ngrok / ngrok-java

Embed ngrok secure ingress into your Java apps with a single line of code.
Other
27 stars 8 forks source link

`Connection.inetAddress()` fails for IPv6 addresses #30

Closed angusholder closed 11 months ago

angusholder commented 11 months ago

Here's a minimal repro

package com.example

import com.ngrok.Connection
import com.ngrok.Listener
import com.ngrok.Session

fun main() {
    val session: Session = Session.withAuthtoken("...").connect()

    session.use {
        val listener: Listener.Edge = session.edge()
            .label("edge", "...")
            .listen()

        listener.use {
            while (true) {
                // Accept a new connection
                val conn: Connection.Edge = listener.accept()

                println("conn.getRemoteAddr() = ${conn.remoteAddr}")
                println("conn.inetAddress() = ${conn.inetAddress()}") // Crashes
            }
        }
    }
}

And the log output from running it

conn.getRemoteAddr() = [2a00:23c8:a8dd:e501:b02c:ea1a:83cf:395e]:64440
Exception in thread "main" java.lang.NumberFormatException: For input string: "23c8"
    at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
    at java.base/java.lang.Integer.parseInt(Integer.java:668)
    at java.base/java.lang.Integer.parseInt(Integer.java:786)
    at com.ngrok.Connection.inetAddress(Connection.java:25)
    at com.example.NgrokIPV6ReproKt.main(NgrokIPV6Repro.kt:21)
    at com.example.NgrokIPV6ReproKt.main(NgrokIPV6Repro.kt)
nikolay-ngrok commented 11 months ago

Hi @angusholder ,

Thanks for using ngrok-java and reporting this issue. Indeed, we should be using the last column : as a divider between the host and the port of an address, before passing it to InetAddress to create one. Therefore, I've created a PR #31 that amends the logic to do so. Don't hesitate to reach out if you have any other issues or comments with our library.

angusholder commented 11 months ago

Thanks!

nikolay-ngrok commented 11 months ago

@angusholder - we've released v0.4.1 which contains the above fix. Thanks for reporting!