Skip to content

Avoid null ptr dereferences for BlameHunk missing Signatures#1254

Merged
weihanglo merged 2 commits into
rust-lang:mainfrom
DanielEScherzer:blame-hunk-null-sig
May 15, 2026
Merged

Avoid null ptr dereferences for BlameHunk missing Signatures#1254
weihanglo merged 2 commits into
rust-lang:mainfrom
DanielEScherzer:blame-hunk-null-sig

Conversation

@DanielEScherzer
Copy link
Copy Markdown
Contributor

@DanielEScherzer DanielEScherzer commented May 13, 2026

Fixes #1253

When a `BlameHunk` is created from an arbitrary buffer via
`Blame::blame_buffer()`, the original and final committer and author can be
missing. This leads to creating `Signature` objects holding null pointers;
subsequent attempts to access the name or email of the signature leads to null
pointer dereferences.

The new tests are currently failing and exists to show the error - they could
not be split up and marked with `#[should_panic]`, which does not appear to
work here. This may be because the error message is that "thread caused
non-unwinding panic. aborting." after the null pointer is dereferenced, and the
attribute only works with unwinding panics, I'm not sure.

The test also confirms that the non-signature methods still work with arbitrary
hunks.
The `BlameHunk` might have null pointers for the original and final committer
and author. The following methods now return an `Option<Signature<'_>>` rather
than a `Signature<'_>`

* `BlameHunk::final_signature()`
* `BlameHunk::final_committer()`
* `BlameHunk::orig_signature()`
* `BlameHunk::orig_committer()`

Fixes rust-lang#1253
@rustbot rustbot added the S-waiting-on-review Status: Waiting on review label May 13, 2026
Copy link
Copy Markdown
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weihanglo weihanglo added this pull request to the merge queue May 15, 2026
Merged via the queue into rust-lang:main with commit 19948b7 May 15, 2026
7 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Waiting on review label May 15, 2026
@DanielEScherzer DanielEScherzer deleted the blame-hunk-null-sig branch May 16, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Null ptr dereference from Blame::blame_buffer() methods

3 participants