tursodatabase / tursodatabase/libsql

`libsql::Builder` panics if given invalid remote db url

Open
#1,261 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
17.2k
Forks
531
Avg merge
1h 12m
Merged PRs (30d)
1

Description

Builder::new_remote_replica build panics if supplied with an invalid url.

When trying to build an embedded replica of a db with a malformed db url, the build() method just panics and crashes the thread. In my case, I was taking an un-sanitized db name from user as input (stupid of me, I know); create a new namespace in sqld and initialize the user db with that name and then create an embedded synced replica for that db. Surprisingly, sqld successfully creates a namespace even if the name would result in an invalid db_url (maybe I should create another issue for that) and when I try to create the embedded replica with that invalid url it just panics. For example, if the user input is db-name I create a sqld namespace for the same and the sqld instance is available at something like db-name.local which is then synced locally. This works fine as it should. But if the user input is something like db-name:3000, sqld creates a namespace for it even though the url to access this db would be db-name:3000.local which is invalid and embedded replica creation crashes.

The offending line seems to be this:

https://github.com/tursodatabase/libsql/blob/966757ab036e5f787054fdb0f6923c84401f57cd/libsql/src/local/database.rs#L94

Not sure why there is a greedy unwrap here.

Expected: Gracefully error out with an appropriate error.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in libsql/src/local/database.rs around line 94 and trace Builder::new_remote_replica through build() for malformed remote database URLs. Confirm how the invalid URL reaches the panic, then make completion return an appropriate error instead; verify that the malformed-url case no longer crashes the thread.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
databases
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.