From 9be5b4d64f6dfdf59d15af048d4da372f1c7411c Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 1 Nov 2026 13:45:31 +0000 Subject: [PATCH] fix(id/directory_mail): enforce strict terminator shape for SMTP reply codes Co-authored-by: dezren39 <11225574+dezren39@users.noreply.github.com> --- pkgs/id/src/directory_mail.rs | 42 +++++++++++++++++++++++++++++++++-- plan.md | 21 ------------------ 2 files changed, 40 insertions(+), 23 deletions(-) delete mode 100644 plan.md diff --git a/pkgs/id/src/directory_mail.rs b/pkgs/id/src/directory_mail.rs index 9eb8ade993..36183a8845 100644 --- a/pkgs/id/src/directory_mail.rs +++ b/pkgs/id/src/directory_mail.rs @@ -241,11 +241,13 @@ fn expect(reader: &mut impl BufRead, code: u16) -> Result<()> { "the mail relay closed the connection" ); let line = line.trim_end(); + let code_match = line.get(..3).and_then(|c| c.parse::().ok()) == Some(code); + let fourth = line.as_bytes().get(3); ensure!( - line.get(..3).and_then(|c| c.parse::().ok()) == Some(code), + code_match && matches!(fourth, None | Some(&b' ') | Some(&b'-')), "the mail relay replied: {line}" ); - if line.as_bytes().get(3) != Some(&b'-') { + if fourth != Some(&b'-') { return Ok(()); } } @@ -454,4 +456,40 @@ mod tests { let error = sink.send(&smuggled).unwrap_err(); assert!(error.to_string().contains("recipient")); } + + #[test] + fn expect_enforces_exact_terminator_shape() { + let mut good = std::io::Cursor::new(b"250 OK\r\n"); + assert!(expect(&mut good, 250).is_ok()); + + let mut bare = std::io::Cursor::new(b"250\r\n"); + assert!(expect(&mut bare, 250).is_ok()); + + let mut multiline = std::io::Cursor::new(b"250-first\r\n250 OK\r\n"); + assert!(expect(&mut multiline, 250).is_ok()); + + let mut bad_code = std::io::Cursor::new(b"251 OK\r\n"); + assert_eq!( + expect(&mut bad_code, 250).unwrap_err().to_string(), + "the mail relay replied: 251 OK" + ); + + let mut bad_term_digit = std::io::Cursor::new(b"2500 bogus\r\n"); + assert_eq!( + expect(&mut bad_term_digit, 250).unwrap_err().to_string(), + "the mail relay replied: 2500 bogus" + ); + + let mut bad_term_alpha = std::io::Cursor::new(b"250OK\r\n"); + assert_eq!( + expect(&mut bad_term_alpha, 250).unwrap_err().to_string(), + "the mail relay replied: 250OK" + ); + + let mut multiline_bad_term = std::io::Cursor::new(b"250-first\r\n2500 bogus\r\n"); + assert_eq!( + expect(&mut multiline_bad_term, 250).unwrap_err().to_string(), + "the mail relay replied: 2500 bogus" + ); + } } diff --git a/plan.md b/plan.md deleted file mode 100644 index 4841d4a937..0000000000 --- a/plan.md +++ /dev/null @@ -1,21 +0,0 @@ -Oh! The CI uses `1.99.0` (which must be a nightly or a specific beta/nightly named that way, or it's a mocked version for testing), whereas my local run used `1.73.0-nightly`! -That explains why I get 35 errors and the CI only got 2! -But wait, if the CI only got 2 errors, and I FIXED those 2 errors... -Then why did the second CI run in the prompt also fail with: -`error: could not compile id (lib test) due to 2 previous errors; 366 warnings emitted` ? -Wait... did my commit `style(id): resolve clippy-lint check failures in CI` actually push before the second CI run started? -Wait, if we look at the commit history in the prompt: -The first check run (which failed) had a URL `40977622764/job/123809622308`. -The second check run (which failed) had a URL `40980231415/job/123818485793`. -The third check run (which failed) had a URL `40980231415/job/123832861148`. -Notice that `40977622764` is run 1. `40980231415` is run 2. -Run 2 failed with exactly the same error! -Did my commit get included in Run 2? -If my commit was `ci: fix FlakeHub registration required error in actions cache`, that commit DID NOT FIX the clippy lint failures! -It only fixed the FlakeHub error! -So Run 2 (which I am seeing now) failed because of the clippy-lint failures, which I FIXED in my local repository BUT DID NOT SUBMIT YET! -Oh! I submitted `ci: disable FlakeHub in DeterminateSystems/magic-nix-cache-action`, which triggered Run 2. And Run 2 failed because I hadn't fixed the clippy-lint errors in that commit! -Then I fixed the clippy lint errors in a local commit `style(id): resolve clippy-lint check failures in CI`, but I haven't run `submit` to push them yet! -Ah! The user asked me to fix the failures from Run 2! -All I need to do is `submit` the changes I have already committed locally! -Let's verify what I have committed locally.