Building 70 Projects ranging from beginner to advanced so anyone can β learn from, build upon, use as a reference, or even copy directly. Owned by my cybersecurity company π
Go aicertificationcloud-engineeringcybercybersecuritycybersecurity-analystcybersecurity-certificationcybersecurity-certificationscybersecurity-educationcybersecurity-jobscybersecurity-portfoliocybersecurity-projectscybersecurity-toolsgrchackinglearningpentestingproject-repositoryprojetcspython
fix(lisdex): B79 - the diagnostic was never empty, it began with a blank line
CarterPerez-dev585397956cf6
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/process.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/process.rsindex 22bda7fa..a9a319f7 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/process.rs+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/process.rs@@ -292,7 +292,14 @@ pub fn run(spec: &CommandSpec, timeout: Duration) -> Result<Execution, ProcessErif is_stderr {diagnostic.clone_from(&bytes);}- captured.extend_from_slice(separator.as_bytes());+ // B79. The separator only separates when there is something in front of it. A compiler+ // writes its errors to stderr and nothing at all to stdout, so leading with the banner+ // put a BLANK FIRST LINE on the capture - and `tail` keeps that blank line whenever the+ // whole output is shorter than the window, which rendered `does not compile: ` with+ // seemingly nothing after the colon. The real text was on the following lines all along.+ if !captured.is_empty() {+ captured.extend_from_slice(separator.as_bytes());+ }captured.extend_from_slice(&bytes);}@@ -375,6 +382,38 @@ mod tests {assert!(run.stderr.is_empty());}+ // B79. A compiler writes its errors to stderr and nothing to stdout, which is the shape+ // every failed harness build has. Leading the capture with the stream banner put a BLANK+ // FIRST LINE in front of the only text anyone wants, and `tail` keeps that blank whenever+ // the whole output is shorter than its window - which is how `does not compile: ` came to+ // render with seemingly nothing after the colon while the errors sat on the next lines.+ #[test]+ fn a_command_that_writes_only_to_stderr_does_not_lead_its_capture_with_a_blank_line() {+ let spec = CommandSpec::new("sh").args(["-c", "echo 'cannot find -lcrypto' >&2; exit 1"]);+ let run = run(&spec, Duration::from_secs(10)).unwrap();+ assert!(+ !run.output.starts_with('\n'),+ "capture led with a blank line: {:?}",+ run.output+ );+ assert_eq!(run.tail(12), "cannot find -lcrypto");+ }++ // The isolating control for the arm above: with BOTH streams written, the banner still has+ // to be there, or two interleaved streams read as one. Drop the separator entirely and this+ // goes red while the test above stays green.+ #[test]+ fn the_stream_banner_survives_when_there_is_stdout_in_front_of_it() {+ let spec = CommandSpec::new("sh").args(["-c", "echo out; echo err >&2"]);+ let run = run(&spec, Duration::from_secs(10)).unwrap();+ assert!(+ run.output.contains(STREAM_SEPARATOR.trim()),+ "the two streams ran together: {:?}",+ run.output+ );+ assert!(run.output.starts_with("out"));+ }+#[test]fn a_hung_command_is_killed_at_the_timeout() {let spec = CommandSpec::new("sleep").arg("30");diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/verify.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/verify.rsindex 569e7dcd..c8f60408 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/verify.rs+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/verify.rs@@ -136,6 +136,28 @@ impl Default for Toolchain {}}+// B79. Compilation is 31.1% of all discards - the largest bucket - so this is the message a+// user meets more often than any other, and it was capable of carrying nothing at all.+//+// Two ways it could come out empty and both are closed here. The compiler writes to stderr and+// nothing to stdout, which used to leave a blank first line on the capture; that is fixed at+// the source in `process`, and the trim keeps a blank line the COMPILER emitted from doing the+// same thing. The second way survives any capture fix: `run.success` with no binary on disk+// produces a genuinely empty output, and there is nothing to quote. The command line is always+// available and always actionable - it names the include roots, the archives and the link+// arguments, which is exactly what the original report turned out to be about.+fn compile_diagnostic(run: &process::Execution) -> String {+ let tail = run.tail(DIAGNOSTIC_LINES);+ let trimmed = tail.trim();+ if !trimmed.is_empty() {+ return trimmed.to_owned();+ }+ format!(+ "the compiler wrote no diagnostic; the command was: {}",+ run.command_line+ )+}+// B80. The bench does not get to choose its link scheme; the archives decide it. Every archive// has to carry a numbering of its own for the harness's own instrumentation to be safely// numbered behind it, so ONE bitcode or uninstrumented archive puts the whole link back on the@@ -205,7 +227,7 @@ impl Bench {return Ok(None);}Ok(Some(Rejection::CompileFailed {- diagnostic: run.tail(DIAGNOSTIC_LINES),+ diagnostic: compile_diagnostic(&run),}))}@@ -398,6 +420,71 @@ mod tests {assert!(corpus.invalid.is_empty());}+ // B79. Compilation is the largest discard bucket, so an unactionable message here is the+ // one users meet most. These three pin what the rejection may never be.+ fn execution(output: &str, success: bool) -> process::Execution {+ process::Execution {+ command_line: "afl-clang-lto -I/src h.c -o h.bin /out/libpng16.a".to_owned(),+ code: if success { Some(0) } else { Some(1) },+ success,+ timed_out: false,+ truncated: false,+ output: output.to_owned(),+ stderr: String::new(),+ duration: Duration::from_secs(1),+ }+ }++ #[test]+ fn a_compiler_that_said_something_has_that_something_quoted() {+ let diagnostic = compile_diagnostic(&execution(+ "h.c:8:10: fatal error: 'libarchive/archive.h' file not found\n1 error generated.",+ false,+ ));+ assert!(diagnostic.contains("file not found"));+ assert!(!diagnostic.contains("the command was"));+ }++ // The case no capture fix reaches: the compiler exits 0 and leaves no binary, so there is+ // genuinely nothing to quote. The command line names the include roots and archives, which+ // is what the original report turned out to be about.+ #[test]+ fn a_compiler_that_said_nothing_still_names_the_command_that_failed() {+ let diagnostic = compile_diagnostic(&execution("", true));+ assert!(diagnostic.contains("afl-clang-lto"));+ assert!(diagnostic.contains("-I/src"));+ }++ // Whitespace is not a diagnostic. A capture holding only newlines rendered as an empty+ // message for exactly as long as this rule was missing.+ #[test]+ fn a_diagnostic_of_pure_whitespace_is_treated_as_no_diagnostic_at_all() {+ let diagnostic = compile_diagnostic(&execution("\n \n\n", false));+ assert!(+ diagnostic.contains("the command was"),+ "blank capture rendered as {diagnostic:?}"+ );+ }++ // And the rejection the user actually reads never comes out blank after the colon.+ #[test]+ fn the_rendered_rejection_always_carries_text_after_the_colon() {+ for output in ["", "\n\n", "\n--- stderr ---\ncannot find -lcrypto"] {+ let rejection = Rejection::CompileFailed {+ diagnostic: compile_diagnostic(&execution(output, false)),+ };+ let rendered = rejection.to_string();+ let after = rendered+ .split_once("does not compile: ")+ .expect("the rejection names itself")+ .1;+ assert!(+ !after.trim_start().is_empty() && !after.starts_with('\n'),+ "rendered as {rendered:?}"+ );+ }+ }+// B80's remaining half. The bench does not choose its scheme; the archives do. These four// pin the whole decision table, because every arm of it changes what the oracles may claim.fn archive_of(name: &str, body: &[u8]) -> PathBuf {