🌐
OWASP Foundation
owasp.org › www-community › vulnerabilities › Null_Dereference
Null Dereference | OWASP Foundation
Null-pointer dereference issues can occur through a number of flaws, including race conditions and simple programming omissions. While there are no complete fixes aside from contentious programming, the following steps will go a long way to ensure that null-pointer dereferences do not occur.
🌐
Snyk Learn
learn.snyk.io › home › security education › what is a null dereference? | tutorial & examples
What is a null dereference? | Tutorial & examples | Snyk Learn
August 15, 2024 - In this lesson, you will learn about vulnerabilities stemming from null dereferencing and how to protect your applications against them. We’ll look at how a vulnerable application can be attacked and brought down. After that, we’ll look under the hood at the code that made this possible. We will then update the code to fix the vulnerability.
Discussions

java - how to fix null dereference issue - Stack Overflow
Fortify is giving null dereference error in the following code. can any one suggest me how to fix it, More on stackoverflow.com
🌐 stackoverflow.com
What happens when dereferencing a nullptr?
Dereferencing a null pointer is undefined behavior. In practice, trying to dereference null usually results in a seg-fault, but sometimes the compiler can optimize out the operation entirely. In your example, *p == true; doesn't actually change any of the program state, so the compiler is being smart and removing the extra computation. In the cout line, your program is actually using the result of the computation so it can't be removed. Note: In some cases an aggressive optimizer may recognize that dereferencing a null pointer would be undefined behavior and assume that the pointer therefore cannot be null. This can lead to some unintuitive and hard to find bugs. More on reddit.com
🌐 r/cpp_questions
20
14
August 18, 2022
java - Explanation and fix for Possible null pointer dereference of - Stack Overflow
There is a branch of statement that, if executed, guarantees that a null value will be dereferenced, which would generate a NullPointerException when the code is executed. Of course, the problem might be that the branch or statement is infeasible and that the NullPointerException cannot ever ... More on stackoverflow.com
🌐 stackoverflow.com
March 21, 2012
java - fix Possible null pointer dereference - Stack Overflow
Possible null pointer dereference due to return value of called method More on stackoverflow.com
🌐 stackoverflow.com
June 26, 2018
🌐
MathWorks
mathworks.com › polyspace bug finder › reviewing and reporting results › polyspace bug finder results › defects › static memory defects
Dereference of a null pointer - NULL pointer dereferenced - MATLAB
If the issue occurs despite an earlier check for NULL, look for intermediate events between the check and the subsequent dereference. Often the result details (or source code tooltips in Polyspace as You Code™) show a sequence of events that led to the defect. You can implement the fix on any ...
🌐
Omi AI
omi.me › blogs › firmware-guides › how-to-fix-null-pointer-dereferencing-step-by-step-guide
How to Fix Null Pointer Dereferencing: Step-by-Step Guide – Omi AI
October 25, 2024 - Learn to fix null pointer dereferencing in C with our step-by-step guide. Enhance firmware stability and prevent crashes efficiently with practical solutions.
🌐
Stack Overflow
stackoverflow.com › questions › 23336905 › how-to-fix-null-dereference-issue
java - how to fix null dereference issue - Stack Overflow
Fortify is giving null dereference error in the following code. can any one suggest me how to fix it, Thanks in advance. public byte[] toByteArray(Notification nd) throws EmailProviderException {...
🌐
GitHub
github.com › dotnet › roslyn › issues › 34408
Fix message "Possible dereference of a null reference" · Issue #34408 · dotnet/roslyn
March 25, 2019 - Area-CompilersConcept-Diagnostic ClarityThe issues deals with the ease of understanding of errors and warnings.The issues deals with the ease of understanding of errors and warnings.Feature - Nullable Reference TypesNullable Reference TypesNullable Reference TypesResolution-FixedThe bug has been fixed and/or the requested behavior has been implementedThe bug has been fixed and/or the requested behavior has been implemented ... The dereference is certain.
Author: dotnet
Find elsewhere
🌐
Mayhem Security
mayhem.security › blog › what-is-null-pointer-dereference
What Is Null Pointer Dereference? | Mayhem
June 1, 2022 - There are a few ways to avoid null pointer dereferences. One is to use a language that does not allow them, such as Java. Another is to always check pointers for NULL before dereferencing them.
🌐
PVS-Studio
pvs-studio.com › en › blog › posts › csharp › 1049
NullReferenceException in C#. What is it and how to fix it?
May 2, 2023 - Adding a check for null inequality is the easiest way to avoid NullReferenceException. However, sometimes such a fix will not solve the original problem, but only mask it. So when fixing code, it is useful to think about whether adding a check ...
🌐
Reddit
reddit.com › r/cpp_questions › what happens when dereferencing a nullptr?
r/cpp_questions on Reddit: What happens when dereferencing a nullptr?
August 18, 2022 -

I saw this code in A Tour of C++, but with a bit modify for illustration:

#include <iostream>

int main() {
  char s = 'a';
  char *p = &s;
  while (*p) {
    std::cout << *p;
    p++;
  }
  p = nullptr;
  //std::cout << (*p == true);
  *p == true;
}

I do not know how does while (*p) { end while I do not know what happens when p is nullptr. And std::cout << (*p == true) will induce segment fault but *p == true does not.

🌐
Stack Overflow
stackoverflow.com › questions › 51031986 › fix-possible-null-pointer-dereference
java - fix Possible null pointer dereference - Stack Overflow
June 26, 2018 - protected void writeStream(final InputStream inputStream, final Path destinationFile) throws IOException { final Path parentDirectory = destinationFile.getParent(); Path tempFile = null; try { // Create the temporary dir for temporary download Files.createDirectories(getTempDownloadPath()); Files.createDirectories(parentDirectory); // Create the temporary file in the temporary dir tempFile = Files.createTempFile(getTempDownloadPath(), destinationFile.getFileName().toString(), ".tmp"); long t1 = System.currentTimeMillis(); Files.copy(inputStream, tempFile, REPLACE_EXISTING); long t2 = System.cu
🌐
Coderanch
coderanch.com › t › 563727 › java › explain-null-pointer-dereference
please explain null pointer dereference [Solved] (Java in General forum at Coderanch)
January 6, 2012 - I suspect that 'line 5' is actually line 9, and it's trying to tell you that if (id != null || id.length() > 0) { should be if (id != null && id.length() > 0) { (at least I assume so; it's certainly an error) Winston · "Leadership is nature's way of removing morons from the productive flow" - Dogbert Articles by Winston can be found here · J. Kevin Robbins ... Thanks, you are correct, I meant line 9 and I see the error now. But what exactly does it mean to "dereference a null pointer"?
🌐
Sivanesh Waran
sivaneshwaran.com › home › klocwork › null pointer dereference in c
Null Pointer Dereference in C Null Pointer Dereference in C
May 5, 2023 - Code Annotations: Developers can use annotations to help Klocwork better understand the code and detect null pointer dereference errors. Code Review: Klocwork can be integrated with code review tools, allowing developers to review and fix null pointer dereference errors before they are committed to the code repository.
Top answer
1 of 8
118

A NULL pointer points to memory that doesn't exist. This may be address 0x00000000 or any other implementation-defined value (as long as it can never be a real address). Dereferencing it means trying to access whatever is pointed to by the pointer. The * operator is the dereferencing operator:

int a, b, c; // some integers
int *pi;     // a pointer to an integer

a = 5;
pi = &a; // pi points to a
b = *pi; // b is now 5
pi = NULL;
c = *pi; // this is a NULL pointer dereference

This is exactly the same thing as a NullReferenceException in C#, except that pointers in C can point to any data object, even elements inside an array.

2 of 8
56

Dereferencing just means accessing the memory value at a given address. So when you have a pointer to something, to dereference the pointer means to read or write the data that the pointer points to.

In C, the unary * operator is the dereferencing operator. If x is a pointer, then *x is what x points to. The unary & operator is the address-of operator. If x is anything, then &x is the address at which x is stored in memory. The * and & operators are inverses of each other: if x is any data, and y is any pointer, then these equations are always true:

*(&x) == x
&(*y) == y

A null pointer is a pointer that does not point to any valid data (but it is not the only such pointer). The C standard says that it is undefined behavior to dereference a null pointer. This means that absolutely anything could happen: the program could crash, it could continue working silently, or it could erase your hard drive (although that's rather unlikely).

In most implementations, you will get a "segmentation fault" or "access violation" if you try to do so, which will almost always result in your program being terminated by the operating system. Here's one way a null pointer could be dereferenced:

int *x = NULL;  // x is a null pointer
int y = *x;     // CRASH: dereference x, trying to read it
*x = 0;         // CRASH: dereference x, trying to write it

And yes, dereferencing a null pointer is pretty much exactly like a NullReferenceException in C# (or a NullPointerException in Java), except that the langauge standard is a little more helpful here. In C#, dereferencing a null reference has well-defined behavior: it always throws a NullReferenceException. There's no way that your program could continue working silently or erase your hard drive like in C (unless there's a bug in the language runtime, but again that's incredibly unlikely as well).

🌐
GitHub
github.com › DaveGamble › cJSON › pull › 519
fix a possible dereference of null pointer by Alanscut · Pull Request #519 · DaveGamble/cJSON
1.7.18 (May 13, 2024) ====== * Add NULL check to cJSON_SetValuestring()(CVE-2024-31755), see #839 and #840 * Remove non-functional list handling of compiler flags, see #851 * Fix heap buffer overflow, see #852 * Remove misused optimization flag -01, see #854 * Set free'd pointers to NULL whenever they are not reassigned immediately after, see #855 and #833 1.7.17 (Dec 26, 2023) ====== * Fix null reference in cJSON_SetValuestring(CVE-2023-50472), see #809 * Fix null reference in cJSON_InsertItemInArray(CVE-2023-50471), see #809 and #810 1.7.16 (Jul 5, 2023) ====== * Add an option for ENABLE_CJS
Author: DaveGamble
🌐
White Knight Labs
whiteknightlabs.com › 2025 › 06 › 24 › understanding-null-pointer-dereference-in-windows-kernel-drivers
Understanding Null Pointer Dereference in Windows Kernel Drivers | White Knight Labs
June 24, 2025 - In this blog post, we'll explore one of the classic yet dangerous bugs—null pointer dereference. We’ll break down what it really means, build a custom