DEV Community

Cover image for CrowdStrike -- how the null pointer cloud have be prevent with Rust
MORDECAI ETUKUDO
MORDECAI ETUKUDO

Posted on

CrowdStrike -- how the null pointer cloud have be prevent with Rust

What Happened?

The Error:

  • The program tried to access a piece of memory it shouldn't have.
  • Specifically, it tried to read from an address that doesn't exist or is not allowed, which was "0x000000000000009c".
  • This mistake is known as an "access violation" and it caused the program to crash, leading to a "blue screen of death" (BSOD), which is a serious error in the computer.

Why It Happened:

  • The software didn't properly check if a pointer (a variable that holds a memory address) was null (meaning it points to nothing) before trying to use it.
  • In simpler terms, it's like trying to read a book that isn't there and causing a big mess because of it.

How Rust Could Have Prevented It

Type System:

  • Rust has a powerful type system that helps ensure safety and correctness of the code.
  • For instance, Rust uses an Option<T> enum (a type that can be either Some(value) or None).
  • If a variable can be None, Rust forces you to handle that case explicitly, ensuring you don't try to use something that isn't there.

Pattern Matching:

  • Rust uses pattern matching to handle different cases.
  • When dealing with an Option<T>, Rust programmers must specify what to do if the value is Some or None, thus preventing null pointer errors.

Compile-Time Checks:

  • Rust performs many checks at compile time (before the program runs) to catch potential errors.
  • This means many mistakes that could cause crashes are caught early, making the program safer.

Real-World Impact

  • If the software engineer had written the program in Rust instead of C++, Rust's design would have forced them to handle the case where a pointer could be null.
  • This would have prevented the program from trying to access invalid memory and avoided the crash.

diagrammatic details

WITH OTHER LANGUAGE
c++

WITH RUST

Rust

Top comments (0)