Skip to content

Commit

Permalink
Bring in #234
Browse files Browse the repository at this point in the history
  • Loading branch information
marcua committed Dec 9, 2023
1 parent e38f428 commit 7d236ca
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 44 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ fernet = { version = "0.2.1" }
lettre = { version = "0.10.4", features = ["tokio1-native-tls"] }
quoted_printable = { version = "0.5.0" }
reqwest = { version = "0.11.22", features = ["json"] }
rusqlite = { version = "0.27.0", features = ["bundled"] }
rusqlite = { version = "0.27.0", features = ["bundled", "limits"] }
regex = { version = "1.10.2"}
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0.108" }
serde_repr = { version = "0.1.17" }
sqlx = { version = "0.6.3", features = ["runtime-actix-native-tls", "postgres", "sqlite"] }
toml = { version = "0.8.8" }
tokio = { version = "1.34.0", features = ["macros", "rt"] }
tokio = { version = "1.34.0", features = ["macros", "process", "rt"] }
prefixed-api-key = { version = "0.1.0", features = ["sha2"]}
prettytable-rs = { version = "0.10.0"}

Expand Down
94 changes: 53 additions & 41 deletions src/hosted_db_runner/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/hosted_db_runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rusqlite = { version = "0.27.0" }
rusqlite = { version = "0.27.0", features = ["bundled", "limits"] }
serde = { version = "1.0", features = ["derive"] }
10 changes: 10 additions & 0 deletions src/hosted_db_runner/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use rusqlite;
use rusqlite::config::DbConfig;
use rusqlite::limits::Limit;
use rusqlite::types::ValueRef;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
Expand Down Expand Up @@ -58,6 +60,14 @@ impl From<string::FromUtf8Error> for AybError {

pub fn query_sqlite(path: &PathBuf, query: &str) -> Result<QueryResult, AybError> {
let conn = rusqlite::Connection::open(path)?;

// Disable the usage of ATTACH
// https://www.sqlite.org/lang_attach.html
conn.set_limit(Limit::SQLITE_LIMIT_ATTACHED, 0);
// Prevent queries from deliberately corrupting the database
// https://www.sqlite.org/c3ref/c_dbconfig_defensive.html
conn.db_config(DbConfig::SQLITE_DBCONFIG_DEFENSIVE)?;

let mut prepared = conn.prepare(query)?;
let num_columns = prepared.column_count();
let mut fields: Vec<String> = Vec::new();
Expand Down

0 comments on commit 7d236ca

Please sign in to comment.