fix: retain complete histories with bounded journal capacity and native recovery
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -472,7 +472,30 @@ fn handle(
|
||||
stream.write_all(&bytes)?;
|
||||
Ok(())
|
||||
}
|
||||
fn safe_error_code(error: &anyhow::Error) -> String {
|
||||
if error.chain().any(|cause| {
|
||||
matches!(cause.downcast_ref::<rusqlite::Error>(),
|
||||
Some(rusqlite::Error::SqliteFailure(code, _)) if code.code == rusqlite::ErrorCode::DiskFull)
|
||||
}) {
|
||||
return "JOURNAL_STORAGE_CAPACITY_BLOCKED".into();
|
||||
}
|
||||
let text = error.to_string();
|
||||
if text.len() <= 96
|
||||
&& text
|
||||
.bytes()
|
||||
.all(|b| b.is_ascii_uppercase() || b.is_ascii_digit() || b == b'_')
|
||||
{
|
||||
text
|
||||
} else {
|
||||
"HELPER_VALIDATION_OR_IO_FAILURE".into()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
run().map_err(|error| anyhow::anyhow!(safe_error_code(&error)))
|
||||
}
|
||||
|
||||
fn run() -> Result<()> {
|
||||
let args: Vec<_> = std::env::args_os().skip(1).collect();
|
||||
if args == [std::ffi::OsString::from("--help")] {
|
||||
println!(
|
||||
@@ -607,16 +630,7 @@ fn main() -> Result<()> {
|
||||
&mut sync,
|
||||
&sync_clock,
|
||||
) {
|
||||
let text = error.to_string();
|
||||
let code = if text.len() <= 96
|
||||
&& text
|
||||
.bytes()
|
||||
.all(|b| b.is_ascii_uppercase() || b.is_ascii_digit() || b == b'_')
|
||||
{
|
||||
text.as_str()
|
||||
} else {
|
||||
"HELPER_VALIDATION_OR_IO_FAILURE"
|
||||
};
|
||||
let code = safe_error_code(&error);
|
||||
eprintln!("helper request rejected: {code}");
|
||||
}
|
||||
}
|
||||
@@ -627,6 +641,41 @@ fn main() -> Result<()> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn sqlite_full_is_sanitized_and_failed_transaction_preserves_history() {
|
||||
let db = rusqlite::Connection::open_in_memory().unwrap();
|
||||
rmm_privileged_helper::bounded_journal_capacity(&db).unwrap();
|
||||
db.execute_batch("CREATE TABLE witness(value BLOB);INSERT INTO witness VALUES('retained');PRAGMA max_page_count=4;").unwrap();
|
||||
db.execute_batch("BEGIN;INSERT INTO witness VALUES('must roll back');")
|
||||
.unwrap();
|
||||
let error = db
|
||||
.execute("INSERT INTO witness VALUES(zeroblob(1048576))", [])
|
||||
.unwrap_err();
|
||||
let wrapped = anyhow::Error::new(error).context("private SQL context must never leak");
|
||||
assert_eq!(
|
||||
safe_error_code(&wrapped),
|
||||
"JOURNAL_STORAGE_CAPACITY_BLOCKED"
|
||||
);
|
||||
assert_eq!(
|
||||
db.query_row("SELECT count(*) FROM witness", [], |r| r.get::<_, u32>(0))
|
||||
.unwrap(),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
db.query_row("PRAGMA integrity_check", [], |r| r.get::<_, String>(0))
|
||||
.unwrap(),
|
||||
"ok"
|
||||
);
|
||||
assert_eq!(
|
||||
db.query_row("PRAGMA max_page_count", [], |r| r.get::<_, u32>(0))
|
||||
.unwrap(),
|
||||
4
|
||||
);
|
||||
assert_eq!(
|
||||
safe_error_code(&anyhow::anyhow!("private SQL text")),
|
||||
"HELPER_VALIDATION_OR_IO_FAILURE"
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn apt_only_profile_denies_scripts_services_reboot_and_wrong_shared_state() {
|
||||
let id = uuid::Uuid::new_v4();
|
||||
let mut config:Config=serde_json::from_value(serde_json::json!({"profile":"apt_only",
|
||||
|
||||
Reference in New Issue
Block a user