Debian Codegraph @

tests/mysql/rustsec.rs

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 use sqlxrust-analyzer cargo sqlx 0.8.3 crate/::{Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#, MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#};
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/;
3
•4 //use sqlx_test::new;
5
6 // https://rustsec.org/advisories/RUSTSEC-2024-0363.html
7 //
8 // During the audit the MySQL driver was found to be *unlikely* to be vulnerable to the exploit,
9 // so this just serves as a sanity check.
•10 /*#[sqlx::test]
11 async fn rustsec_2024_0363() -> anyhow::Result<()> {
12 let overflow_len = 4 * 1024 * 1024 * 1024; // 4 GiB
13
14 let padding = " ".repeat(overflow_len);
15
16 let payload = "UPDATE injection_target SET message = 'you''ve been pwned!' WHERE id = 1";
17
18 let mut injected_value = String::with_capacity(overflow_len + payload.len());
19
20 injected_value.push_str(&padding);
21 injected_value.push_str(payload);
22
23 // Since this is so large, keeping it around until the end *can* lead to getting OOM-killed.
24 drop(padding);
25
26 let mut conn = new::<MySql>().await?;
27
28 sqlx::raw_sql(
29 "CREATE TEMPORARY TABLE injection_target(id INTEGER PRIMARY KEY AUTO_INCREMENT, message TEXT);\n\
30 INSERT INTO injection_target(message) VALUES ('existing message');",
31 )
32 .execute(&mut conn)
33 .await?;
34
35 // We can't concatenate a query string together like the other tests
36 // because it would just demonstrate a regular old SQL injection.
37 let res = sqlx::query("INSERT INTO injection_target(message) VALUES (?)")
38 .bind(&injected_value)
39 .execute(&mut conn)
40 .await;
41
42 if let Err(e) = res {
43 // Connection rejected the query; we're happy.
44 //
45 // Current observed behavior is that `mysqld` closes the connection before we're even done
46 // sending the message, giving us a "Broken pipe" error.
47 //
48 // As it turns out, MySQL has a tight limit on packet sizes (even after splitting)
49 // by default: https://dev.mysql.com/doc/refman/8.4/en/packet-too-large.html
50 if matches!(e, Error::Io(ref ioe) if ioe.kind() == io::ErrorKind::BrokenPipe) {
51 return Ok(());
52 }
53
54 panic!("unexpected error: {e:?}");
55 }
56
57 let messages: Vec<String> =
58 sqlx::query_scalar("SELECT message FROM injection_target ORDER BY id")
59 .fetch_all(&mut conn)
60 .await?;
61
62 assert_eq!(messages[0], "existing_message");
63 assert_eq!(messages[1].len(), injected_value.len());
64
65 // Injection didn't affect our database; we're happy.
66 Ok(())
•67 }*/