Skip to content

Commit

Permalink
Always set SQLITE_OPEN_URI
Browse files Browse the repository at this point in the history
  • Loading branch information
LecrisUT committed Aug 31, 2024
1 parent e10789d commit 9fb610a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions sqlx-sqlite/src/connection/establish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use libsqlite3_sys::{
sqlite3_load_extension, sqlite3_open_v2, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, SQLITE_OK,
SQLITE_OPEN_CREATE, SQLITE_OPEN_FULLMUTEX, SQLITE_OPEN_MEMORY, SQLITE_OPEN_NOMUTEX,
SQLITE_OPEN_PRIVATECACHE, SQLITE_OPEN_READONLY, SQLITE_OPEN_READWRITE, SQLITE_OPEN_SHAREDCACHE,
SQLITE_OPEN_URI,
};
use percent_encoding::NON_ALPHANUMERIC;
use sqlx_core::IndexMap;
Expand Down Expand Up @@ -67,11 +68,14 @@ impl EstablishParams {
})?
.to_owned();

// Set common flags we expect to have in sqlite
let mut flags = SQLITE_OPEN_URI;

// By default, we connect to an in-memory database.
// [SQLITE_OPEN_NOMUTEX] will instruct [sqlite3_open_v2] to return an error if it
// cannot satisfy our wish for a thread-safe, lock-free connection object

let mut flags = if options.serialized {
flags |= if options.serialized {
SQLITE_OPEN_FULLMUTEX
} else {
SQLITE_OPEN_NOMUTEX
Expand Down Expand Up @@ -111,7 +115,6 @@ impl EstablishParams {
percent_encoding::percent_encode(filename.as_bytes(), NON_ALPHANUMERIC),
serde_urlencoded::to_string(&query_params).unwrap()
);
flags |= libsqlite3_sys::SQLITE_OPEN_URI;
}

let filename = CString::new(filename).map_err(|_| {
Expand All @@ -131,7 +134,7 @@ impl EstablishParams {
CString::new(e.as_bytes()).map_err(|_| {
io::Error::new(
io::ErrorKind::InvalidData,
"extension entrypoint names passed to SQLite must not contain nul bytes"
"extension entrypoint names passed to SQLite must not contain nul bytes",
)
})
})
Expand Down Expand Up @@ -255,9 +258,9 @@ impl EstablishParams {
))));
}
} // Preempt any hypothetical security issues arising from leaving ENABLE_LOAD_EXTENSION
// on by disabling the flag again once we've loaded all the requested modules.
// Fail-fast (via `?`) if disabling the extension loader didn't work for some reason,
// avoids an unexpected state going undetected.
// on by disabling the flag again once we've loaded all the requested modules.
// Fail-fast (via `?`) if disabling the extension loader didn't work for some reason,
// avoids an unexpected state going undetected.
unsafe {
Self::sqlite3_set_load_extension(
handle.as_ptr(),
Expand Down

0 comments on commit 9fb610a

Please sign in to comment.