diff options
Diffstat (limited to 'src/non_critical')
| -rw-r--r-- | src/non_critical/_tools.c | 10 | ||||
| -rw-r--r-- | src/non_critical/gui_destroyer.rs | 21 | ||||
| -rw-r--r-- | src/non_critical/kern_panic/mod.rs | 11 | ||||
| -rw-r--r-- | src/non_critical/mod.rs | 6 |
4 files changed, 26 insertions, 22 deletions
diff --git a/src/non_critical/_tools.c b/src/non_critical/_tools.c index 4b6159d..967c820 100644 --- a/src/non_critical/_tools.c +++ b/src/non_critical/_tools.c @@ -35,7 +35,15 @@ char* get_os_name() { if (end != NULL) { *end = '\0'; } - return name; + + // Allocate memory for the result and copy the string + char* result = malloc(strlen(name) + 1); + if (result != NULL) { + strcpy(result, name); + } + + fclose(file); + return result; } } diff --git a/src/non_critical/gui_destroyer.rs b/src/non_critical/gui_destroyer.rs index 126f0a6..97ac74e 100644 --- a/src/non_critical/gui_destroyer.rs +++ b/src/non_critical/gui_destroyer.rs @@ -1,15 +1,12 @@ -#![no_main] -#![feature(let_chains)] - use std::ffi::CStr; -use std::io::Write; -use std::ptr; -use std::fs::OpenOptions; -use std::os::unix::io::{AsRawFd, IntoRawFd}; +use std::io::Write; +use std::ptr; +use std::fs::OpenOptions; +use std::os::unix::io::IntoRawFd; use std::os::raw::c_char; use std::error::Error; -use rand::{Rng}; +use rand::Rng; use x11::xlib; use wayland_client::{Display, GlobalManager, Main}; @@ -34,10 +31,10 @@ pub fn artifacts_and_kill(root: bool, iterations: i32) -> Result<(), std::io::Er } let mut fb = std::fs::File::open("/dev/fb0").unwrap(); - let mut rng = rand::thread_rng(); - + let mut rng = rand::rng(); + for _ in 0..iterations { - let garbage: Vec<u8> = (0..1024).map(|_| rng.gen()).collect(); + let garbage: Vec<u8> = (0..1024).map(|_| rng.random()).collect(); let _ = fb.write(&garbage); } @@ -106,7 +103,7 @@ fn wayland_corrupt_buffer() -> Result<(), Box<dyn Error>> { .map_err(|_| "wl_shm not available")?; let tmp_path = std::env::temp_dir().join(format!("wl_broken_{}.tmp", std::process::id())); - let mut f = OpenOptions::new() + let f = OpenOptions::new() .read(true) .write(true) .create(true) diff --git a/src/non_critical/kern_panic/mod.rs b/src/non_critical/kern_panic/mod.rs index 4dccc34..d6accd9 100644 --- a/src/non_critical/kern_panic/mod.rs +++ b/src/non_critical/kern_panic/mod.rs @@ -13,22 +13,23 @@ pub unsafe fn sysrq_panic() { } pub fn kmod_panic() -> Result<(), String> { - let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap_or_else(|_| "target/debug".into())); + let out_dir = PathBuf::from(env::var("OUT_DIR") + .map_err(|_| "OUT_DIR environment variable not set".to_string())?); let ko_file = out_dir.join("linux_kmod.ko"); - + if !ko_file.exists() { return Err(format!("Kernel module not found at: {}", ko_file.display())); } - + let status = Command::new("insmod") .arg(&ko_file) .status() .map_err(|e| format!("Failed to execute insmod: {}", e))?; - + if !status.success() { return Err(format!("Failed to load kernel module: exit code {:?}", status.code())); } - + Ok(()) } diff --git a/src/non_critical/mod.rs b/src/non_critical/mod.rs index 884e0f0..a94ac68 100644 --- a/src/non_critical/mod.rs +++ b/src/non_critical/mod.rs @@ -4,16 +4,14 @@ pub mod kern_panic; use std::os::raw::{c_char, c_int}; extern "C" { - // Tools + // Tools pub fn check_root() -> c_int; - pub fn check_pid(pid: c_int) -> c_int; - pub fn get_os_name() -> *mut c_char; pub fn get_desktop_server() -> *mut c_char; // Random sounds pub fn init_random_sounds(threads: c_int, time: c_int) -> c_int; pub fn stop_random_sounds(); - + // Syscall storm pub fn init_syscall_storm(threads: c_int, iterations: c_int) -> c_int; pub fn stop_syscall_storm(); |
