Skip to content

copy_nonoverlapping panics on zero-sized NULL ptr copy #131371

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
RalfJung opened this issue Oct 7, 2024 · 2 comments · Fixed by #131384
Closed

copy_nonoverlapping panics on zero-sized NULL ptr copy #131371

RalfJung opened this issue Oct 7, 2024 · 2 comments · Fixed by #131384
Assignees
Labels
C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@RalfJung
Copy link
Member

RalfJung commented Oct 7, 2024

We somewhat recently declared copy_nonoverlapping to be legal on a NULL pointer. However, the debug assertions still reject this:

ub_checks::is_aligned_and_not_null(src, align)
&& ub_checks::is_aligned_and_not_null(dst, align)
&& ub_checks::is_nonoverlapping(src, dst, size, count)

Other, related functions have similar problems.

Cc @saethlin

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 7, 2024
@saethlin saethlin added C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 7, 2024
@saethlin
Copy link
Member

saethlin commented Oct 7, 2024

We have a very incomplete test suite for these checks here: https://github.com/rust-lang/rust/tree/master/tests/ui/precondition-checks

We should probably have been adding tests for every errant call that we detect.

@saethlin saethlin self-assigned this Oct 7, 2024
@saethlin
Copy link
Member

saethlin commented Oct 7, 2024

Started working on an implementation here: #131384

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants