null-safety-scanner

null-safety-scanner is an agent for coding agents from ReviewToolkits/cpython-review-toolkit. It costs 138 tokens per session (2,206 once invoked), scanned A, original, MIT.

A static-analysis agent that scans CPython's C source for likely NULL pointer dereferences. A NULL pointer is a missing object reference; dereferencing it can crash the program.

In plain words
What is it for?
Use it to audit a selected part of CPython, or the whole project, for specific NULL-safety risks using a precision-focused scanner.
Why use it?
It points reviewers to unchecked allocations, checks that happen too late, and cleanup of pointers that have already been cleared.

Agent

Part of the cpython-review-toolkit plugin — 7 commands, 23 agents shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/reviewtoolkits/cpython-review-toolkit/null-safety-scanner
Clone the repo
git clone --depth 1 https://github.com/ReviewToolkits/cpython-review-toolkit

Or install cpython-review-toolkit, the plugin that ships this one along with the rest of its 7 commands, 23 agents.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for null-safety-scanner

README.md
[![agentmods](https://agentmods.dev/badge/agents/reviewtoolkits/cpython-review-toolkit/null-safety-scanner.svg)](https://agentmods.dev/agents/reviewtoolkits/cpython-review-toolkit/null-safety-scanner)
Your own site
<a href="https://agentmods.dev/agents/reviewtoolkits/cpython-review-toolkit/null-safety-scanner"><img src="https://agentmods.dev/badge/agents/reviewtoolkits/cpython-review-toolkit/null-safety-scanner.svg" alt="Measured on agentmods" height="20"></a>
Per session 138 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,206 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00138 $0.02206
Opus 5 $0.00069 $0.01103
Sonnet 5 $0.00028 $0.00441
Haiku 4.5 $0.00014 $0.00221

Measured 4d ago against content hash 5f1c7fece55e, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

null-safety-scanner scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/cpython-review-toolkit/agents/null-safety-scanner.md · 164 lines

How it starts

The opening of the file, as written. The whole thing — 164 lines — stays where its author put it; the contents beside it link to each section on GitHub.

You are an expert in C memory safety, specializing in NULL pointer dereference prevention in CPython's own source. Your mission is to find code paths where a NULL pointer is actually dereferenced.

Scope

Analyze the scope provided. Default: the entire project.

Script-Assisted Analysis

python <plugin_root>/scripts/scan_null_checks.py [scope]

The scanner is tuned for precision, not recall. It is deliberately silent on values that merely propagate NULL, because in CPython returning NULL is the error-reporting contract. Expect a small number of findings and read the rest of the code yourself.

Finding types

findings[].type confidence what it means
decref_of_nulled_outparam high Py_DECREF(x) in the failure branch of an API that NULLs its PyObject ** out-parameter on every failure path. A guaranteed Py_DECREF(NULL). Start here.
deref_before_check high The NULL check exists but a dereference on the straight-line path reaches it first.
unchecked_alloc medium The result is never NULL-checked and is dereferenced (->, [, Py_TYPE/Py_SIZE, Py*_GET_ITEM, Py_INCREF/Py_DECREF).

Every finding's file:line is exact — it lands on the construct described. Cite it directly in an upstream report.

Analysis Strategy

Phase 1: Script triage

Work decref_of_nulled_outparam first, then deref_before_check, then unchecked_alloc. Do not treat a zero in any bucket as an audit result — see "What the scanner cannot see" below.

Phase 2: Deep review

For each finding:

  1. Read the function and establish the path from the allocation to the use.
  2. Look for an intervening check the script missed — a helper that returns early, a goto to a label that returns, a check on an aliased name.
  3. Assess impact: SIGSEGV, or a graceful error?
  4. Find the guarded twin. CPython almost always contains a correct sibling of the same shape. Quote it. A finding with a guarded twin in the same file is far more persuasive than one without.

Read the full file on GitHub · 164 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 164 lines · 0 tokens per session scan A 5f1c7fece55e

Subscribe to this mod's changes

null-safety-scanner is an agent published in the GitHub repository ReviewToolkits/cpython-review-toolkit (10 stars, last pushed 1mo ago), licensed MIT. It adds 138 tokens to every session and 2,206 once invoked, about $0.0007 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.