Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Code Smell 260 - Crowdstrike NULL
Maxi Contieri
Maxi Contieri

Posted on • Originally published atmaximilianocontieri.com

     

Code Smell 260 - Crowdstrike NULL

Avoiding the Null Trap in Privilege Mode Drivers

TL;DR: Using null pointers in critical code can crash your system

Problems

  • Memory access violation

  • Unpredictable behavior

  • Null Pointer Dereference

  • Unexpected program termination

  • System instability

  • No healing/recovery strategy

  • Security Risk

Solutions

  1. Avoid usingNULLs

  2. Useaddress sanitizers

  3. Make controlled releases to mission-critical software

  4. Create better rollback strategies instead ofBSOD

  5. Use Smart Pointers: Manage memory automatically and avoid null pointers with smart pointers

  6. Create self-healing software.

  7. Apply defensive programming

  8. Improve your QA tests before deploying to production.

BSOD

Context

When you use nulls in a privileged driver, you risk causing serious issues.

Privilege mode drivers run with high permissions, and if you use a null pointer, the system might try to access an invalid memory address.

For example, trying to read from address 0x9c (156) or using 0x0 as a special value can lead to critical errors.

You can't just abort the program in privileged mode, so you must handle these cases carefully.

In privileged drivers, null pointer usage poses significant risks. You can mitigate these risks using modern C++ features likestd::optional.

This problem caused one of the worst software blackouts in 2024.

Sample Code

Wrong

// This case is not exactly what happened with Crowdstrike// It is here for illustration purposesvoid*get_data(){if(data_available){returndata_ptr;// This could be null!}else{// Uh oh, what if data_ptr is null here?returnNULL;// Using Null to indicate no data// knowing Null is schizophrenic}}intprocess_data(void*data){if(data!=NULL){// Maybe a null check, but not guaranteed!// Accessing data... (crash if data is Null)return*data;}// No check? Silent failure or unexpected behavior.return-1;}
Enter fullscreen modeExit fullscreen mode

Right

// You should ideally replace the null with a polymorphic call// You can see the technique in related articlesstd::unique_ptr<int>get_data(){if(data_available){returnstd::make_unique<int>(data_value);}else{returnnullptr;// Explicitly return nullptr}}intprocess_data(conststd::unique_ptr<int>&data){if(data){// Check for valid pointerreturn*data;}else{// Handle no data case (e.g., return default value)return0;}}
Enter fullscreen modeExit fullscreen mode

Detection

[X] Semi-Automatic

You can detect this smell by checking for null pointer usage in critical parts of your code. Look for functions that process pointers and see if they handle null pointers safely.

Human code reviews are good for checking this kind of problem.

Tags

  • Null

Level

[x] Advanced

AI Generation

AI generators can sometimes produce this smell, especially if they generate code without context about the environment where the code will run.

AI generators are fed with code with NULL usage even thoughhis creator told us to avoid it altogether.

AI Detection

AI tools can detect this smell with specific instructions.

AI can be trained to identify code patterns.

Teaching it the nuances of privileged driver development and null safety best practices might require more advanced techniques.

Use static analysis tools to flag null pointer dereferences.

Conclusion

Voyager 1's software has been running for more than 50 years.

It was designed to be robust, reliable, and redundant which is sadly uncommon in some immature systems in 2024.

Avoid using null pointers in privileged mode drivers.

I have written a book onclean code and a whole chapter#15 on how to avoid NULL and all the consequences it carries.

Hopefully, Crowdstrike engineers will read it!

Relations

More Info


This article is part of the CodeSmell Series.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Learn something new every day. - I am a senior software engineer working in industry, teaching and writing on software design, SOLID principles, DDD and TDD.
  • Location
    Buenos Aires
  • Education
    Computer Science Degree at Universidad de Buenos Aires
  • Pronouns
    He/Him
  • Work
    Senior Software Engineer at Avature
  • Joined

More fromMaxi Contieri

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp