🌐
Python
bugs.python.org › issue41995
Issue 41995: five possible Null Pointer Dereference bugs. - Python tracker
This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide · This issue has been migrated to GitHub: https://github.com/python/cpython/issues/86161
🌐
Python
bugs.python.org › issue24044
Issue 24044: NULL pointer dereference in listsort() with key function - Python tracker
April 23, 2015 - This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide · This issue has been migrated to GitHub: https://github.com/python/cpython/issues/68232
🌐
Python
bugs.python.org › issue34987
Issue 34987: A possible null pointer dereference in _pickle.c's save_reduce() - Python tracker
October 15, 2018 - This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide · This issue has been migrated to GitHub: https://github.com/python/cpython/issues/79168
🌐
GitHub
github.com › python › cpython › issues › 126106
Potential null pointer dereference in `PySSLSession_richcompare` · Issue #126106 · python/cpython
October 29, 2024 - Bug report Bug description: Pointer left is dereferenced here, but null-pointer check is done later. Correct code should look like this: int result; if (left == NULL || right == NULL) { PyErr_BadInternalCall(); return NULL; } PyTypeObjec...
Author: python
🌐
Python
bugs.python.org › issue27826
Issue 27826: Null-pointer dereference in tuplehash() function - Python tracker
This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide · This issue has been migrated to GitHub: https://github.com/python/cpython/issues/72013
🌐
Python
bugs.python.org › issue34824
Issue 34824: _ssl.c: Possible null pointer dereference - Python tracker
September 27, 2018 - This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide · This issue has been migrated to GitHub: https://github.com/python/cpython/issues/79005
🌐
Python
bugs.python.org › issue36374
Issue 36374: A possible null pointer dereference in compile.c's merge_consts_recursive() - Python tracker
March 19, 2019 - This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide · This issue has been migrated to GitHub: https://github.com/python/cpython/issues/80555
Top answer
1 of 8
20

EDIT 2021:

There is a new package that is sort of a hack featuring exactly this functionality in Python. Here is the repo: https://github.com/iann838/nullsafe-python

from nullsafe import undefined, _

value = _(variable).method()
assert value is undefined
assert not value
assert value == None

Works with AttributeError and KeyError aswell

dic = {}
assert _(dic)["nah"] is undefined
assert _(dic).nah is undefined

The wrapped object typings will remain effective.


  1. No, there isn't.

  2. But to check for None, you don't write if x:, you write if x is None:. This is an important distinction - x evaluates to False for quite a few values that are propably perfectly valid (most notably 0-equivalent numbers and empty collections), whereas x is None only evaluates to True if the reference x points to the singleton object None.

  3. From personal experience, such an operator would be needed very rarely. Yes, None is sometimes used to indicate no value. But somehow - maybe because idiomatic code returns null objects where sensible or throws exceptions to indicate critical failure - I only get an AttributeError: 'NoneType' object has no attribute '...' twice a month.

  4. I would argue that this might be a misfeature. null has two meanings - "forgot to initialize" and "no data". The first is an error and should throw an exception. The second case usually requires more elaborate handling than "let's just not call this method". When I ask the database/ORM for a UserProfile, it's not there and I get null instead... do I want to silently skip the rest of the method? Or do I really want to (when in "library code") throw an approriate exception (so "the user (code)" knows the user isn't there and can react... or ignore it) or (when I'm coding a specific feature) show a sensible message ("That user doesn't exist, you can't add it to your friend list") to the user?

2 of 8
20

First of all, your options depend on what you'd like the expression to evaluate to if the variable is not dereferencable. I'll assume None is the appropriate result in these examples.

A common idiom for some circumstances in Python uses conditional expressions:

variable.method() if variable is not None else None

While this need may not be widespread, there are circumstances where it would be useful, especially when the references are nested and you would want something like this, where that idiom quickly gets cumbersome.

a?.b?.c?.d

Note that support for a ?. operator for safe deferencing is one of the main topics of PEP 505: None-aware operators \| Python.org. It's current status is "deferred".

Some discussion of it is at:

  • PEP 505: Bringing None-Aware Operators to Python \| Hacker News
🌐
GitHub
github.com › python › cpython › issues › 96582
Possible NULL pointer dereference in _PyThread_CurrentFrames · Issue #96582 · python/cpython
September 5, 2022 - _PyThread_CurrentFrames does not properly handles malloc failure in _PyFrame_GetFrameObject as it is lazily allocated when requested.
Author: python
Find elsewhere
🌐
Python
bugs.python.org › issue24704
Issue 24704: Dereferencing a Null Pointer - Python tracker
This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide · This issue has been migrated to GitHub: https://github.com/python/cpython/issues/68892
🌐
Cybersecurity Help
cybersecurity-help.cz › vulnerabilities › 17805
NULL pointer dereference in Python - CVE-2019-5010
July 4, 2020 - A remote attacker can send a request to initiate a Transport Layer Security (TLS) connection using an X509 certificate that submits malicious input, trigger a NULL pointer dereference condition that causes the application to crash, resulting in a DoS condition. Python Amazon Linux AMI Gentoo Linux Fedora Red Hat Enterprise Linux for Scientific Computing Red Hat Enterprise Linux for IBM z Systems Red Hat Enterprise Linux Desktop Red Hat Enterprise Linux Workstation Red Hat Enterprise Linux Server Red Hat Enterprise Linux for x86_64 Slackware Linux Ubuntu Opensuse Red Hat Software Collections py
🌐
GitHub
github.com › python › cpython › issues › 126108
Potential null pointer dereference in `PySys_AddWarnOptionUnicode` · Issue #126108 · python/cpython
October 29, 2024 - Bug report Bug description: Pointer tstate is compared to a NULL value here, but above there is a dereference. Stack trace: _PySys_AddWarnOptionWithError -> get_warnoptions -> _PySys_GetAttr. Correct code should look like this: void PySy...
Author: python
🌐
GitHub
github.com › python › cpython › issues › 126240
Possible null pointer dereference of variable args in _PyPegen_collect_call_seqs · Issue #126240 · python/cpython
October 31, 2024 - Crash report What happened? args can be NULL as a result of _Py_asdl_expr_seq_new, and then dereference happens. Return value of _Py_asdl_expr_seq_new` is usually checked, for example here and in o...
Author: python
🌐
Tenable
tenable.com › plugins › nessus › 123144
FreeBSD : Python -- NULL pointer dereference vulnerability (d7...<!-- --> | Tenable®
March 27, 2019 - Python Changelog : bpo-35746: [CVE-2019-5010] Fix a NULL pointer deref in ssl module. The cert parser did not handle CRL distribution points with empty DP or URI correctly. A malicious or buggy certificate can result into segfault.
🌐
Openssf
best.openssf.org › Secure-Coding-Guide-for-Python › CWE-703 › CWE-476
CWE-476: NULL Pointer Dereference | OpenSSF Best Practices Working Group
The code example attempts to directly call len() on a non-array value, in this case on None, which will raise a TypeError. Such unchecked dereferencing of a None value could result in an application crash or denial of service, impacting system availability.
🌐
Python
docs.python.org › 2.5 › lib › ctypes-pointers.html
14.14.1.14 Pointers
December 23, 2008 - >>> null_ptr = POINTER(c_int)() >>> print bool(null_ptr) False >>> ctypes checks for NULL when dereferencing pointers (but dereferencing non-NULL pointers would crash Python):
🌐
Snyk
security.snyk.io › snyk vulnerability database › pip
NULL Pointer Dereference in tensorflow | CVE-2022-23570 | Snyk
February 7, 2022 - In the first case execution proceeds to the dereferencing of the null pointer, whereas in the second case it results in a crash due to the assertion failure.
🌐
Red Hat
bugzilla.redhat.com › show_bug.cgi
1666519 – (CVE-2019-5010) CVE-2019-5010 python: NULL pointer dereference using a specially crafted X509 certificate
Red Hat Bugzilla – Bug 1666519 · This site requires JavaScript to be enabled to function correctly, please enable it · Privacy Contact FAQ Legal
🌐
GitHub
github.com › python › cpython › issues › 142594
Null pointer dereference in `TextIOWrapper.close()` via re-entrant `closed` property that detaches `buffer` · Issue #142594 · python/cpython
December 11, 2025 - TextIOWrapper.close() queries the stream’s closed property. A user-defined RawIOBase.closed can re-enter and call wrapper.detach(), clearing self->buffer. The function then continues and calls self->buffer.close() on a NULL pointer, leading to a null-pointer dereference in _PyObject_GetMethod/_Py_TYPE.
Author: python
🌐
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 languages that use pointers, ... use pointers, such as Java and Python, null dereferences may not cause the program to crash, but can still lead to runtime errors ......