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

bug report:"App crashes on invalid username input instead of throwing an error #534

Open
chainray01 opened this issue Jan 23, 2025 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@chainray01
Copy link

Describe the issue

When entering an invalid username, the application crashes with the following error: Fatal error: Range requires lowerBound <= upperBound.

Vapor version

2.13.5

Operating system and version

macos 13.7.6

Swift version

Swift Package Manager - Swift 5.9.0

Steps to reproduce

1.Enter an invalid username
2. run code
do { _ = try await pool.withConnection { conn in conn.simpleQuery("SELECT 1") }.get() } catch { throw error }

Outcome

App crashes
Swift/arm64e-apple-macos.swiftinterface:5830: Fatal error: Range requires lowerBound <= upperBound

Image

Additional notes

No response

@chainray01 chainray01 added the bug Something isn't working label Jan 23, 2025
@gwynne gwynne self-assigned this Jan 23, 2025
@0xTim 0xTim transferred this issue from vapor/postgres-kit Jan 28, 2025
@chainray01
Copy link
Author

@gwynne soft reminder

@fabianfett
Copy link
Collaborator

I just tried to repro this with this test case:

func testCrash2() async throws {
    var mlogger = Logger(label: "test")
    mlogger.logLevel = .debug
    let logger = mlogger
    let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 8)
    self.addTeardownBlock {
        try await eventLoopGroup.shutdownGracefully()
    }

    var clientConfig = PostgresClient.Configuration.makeTestConfiguration()
    clientConfig.username = "wrong"
    let client = PostgresClient(configuration: clientConfig, eventLoopGroup: eventLoopGroup, backgroundLogger: logger)
    do {
        try await withThrowingTaskGroup(of: Void.self) { taskGroup in
            taskGroup.addTask {
                await client.run()
            }

            do {
                _ = try await client.withConnection { conn in
                    conn.simpleQuery("SELECT 1") }.get()
            } catch {
                throw error
            }

            taskGroup.cancelAll()
        }
    } catch {
        XCTFail("Unexpected error: \(String(reflecting: error))")
    }
}

Sadly, no luck!

Observations:

  • With a wrong username we shouldn't even enter the sasl handshake dance. The Postgres server rejects the startup message right away.

@chainray01 Which Postgres version do you use? Which PostgresNIO version do you use? What is the username and password that you use? (Please change it after disclosing it here, but I need it to repro your crash I'm afraid.)

@chainray01
Copy link
Author

@fabianfett Postgres version 17,PostgresKit 2.13.5,username:dev_owner1

Kapture.2025-04-09.at.16.00.24.webm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants