patterns-rust.md

March 13, 2024 ยท View on GitHub

IDLanguageTitleSeverityDescriptionSuggested FixContext
RUST001Rust[Rust] Unsafe code blockHighUnsafe code blocks can lead to undefined behavior if not used properly.Ensure that unsafe code is necessary and properly reviewed. Use safe abstractions when possible.Whenever using unsafe blocks in Rust code
RUST002Rust[Rust] Unhandled errorMediumUnwrapping a Result or Option without proper error handling can lead to panic.Use match or if let to handle the Result or Option properly, or use ? to propagate the error.When using unwrap() on Result or Option types
RUST003Rust[Rust] Unchecked arithmeticMediumArithmetic operations that can overflow or underflow without being checked.Use checked arithmetic methods like checked_add, checked_sub, checked_mul, and checked_div.When performing arithmetic operations that may overflow or underflow
RUST004Rust[Rust] Insecure random number generatorHighUsing an insecure random number generator for security-sensitive operations.Use a cryptographically secure random number generator like rand::ThreadRng or ring::rand::SystemRandom.When generating random numbers for security-sensitive purposes
RUST005Rust[Rust] Uninitialized memoryHighUsing uninitialized memory can lead to undefined behavior.Initialize memory properly or use mem::MaybeUninit for delayed initialization.When working with uninitialized memory
RUST006Rust[Rust] Use of mem::transmuteHighUsing mem::transmute can lead to undefined behavior and violate type safety.Avoid using mem::transmute and use safe type conversions or as keyword for primitive types.When using mem::transmute to reinterpret memory
RUST007Rust[Rust] Use of std::process::CommandMediumUsing std::process::Command without properly sanitizing user input can lead to command injection vulnerabilities.Properly sanitize and validate user input before passing it to std::process::Command. Consider using safe wrappers or libraries.When executing external commands or processes
RUST008Rust[Rust] Use of std::fs::File with unwrap()MediumUsing unwrap() with std::fs::File can lead to panics if the file operation fails.Use ? operator to propagate the error or handle it explicitly with match or if let.When opening files using std::fs::File
RUST009Rust[Rust] Deserialization of untrusted dataHighDeserializing untrusted data without proper validation can lead to security vulnerabilities.Implement custom deserialization logic with proper validation and sanitization of untrusted data. Consider using safe deserialization libraries.When deserializing data from untrusted sources using serde or other libraries
RUST010Rust[Rust] Use of std::net::TcpListener with unwrap()MediumUsing unwrap() with std::net::TcpListener can lead to panics if the binding operation fails.Use ? operator to propagate the error or handle it explicitly with match or if let.When binding to a network address using std::net::TcpListener'. From the beginning to end!