Skip to content

libutil: reject borrowing URL accessors on temporaries - #16337

Open
domenkozar wants to merge 1 commit into
NixOS:masterfrom
cachix:local-pr/url-accessor-lifetime-dcb494e63
Open

libutil: reject borrowing URL accessors on temporaries#16337
domenkozar wants to merge 1 commit into
NixOS:masterfrom
cachix:local-pr/url-accessor-lifetime-dcb494e63

Conversation

@domenkozar

Copy link
Copy Markdown
Member

VerbatimURL::scheme() and ParsedURL::pathSegments() return non-owning views into the object they are called on. However, their const & qualifiers still allow calls on rvalues. If a returned view is retained past the end of that full expression, it refers to an already-destroyed URL.

Add deleted const && overloads so these unsafe calls are rejected at compile time. Callers must keep the owning URL alive; update the path-segment test accordingly.

Assisted-by: Claude Code (Claude Opus 5)

Motivation

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@domenkozar
domenkozar requested a review from edolstra as a code owner August 20, 2026 21:43
Comment thread src/libutil/include/nix/util/url.hh Outdated
Comment thread src/libutil-tests/url.cc
`VerbatimURL::scheme()` and `ParsedURL::pathSegments()` return non-owning
views into the object they are called on. Their `const &` qualifiers also
bind to rvalues, so a temporary URL can hand out a view that dangles as
soon as the enclosing full expression ends.

Add deleted rvalue-qualified overloads so those calls are rejected at
compile time. This also rejects rvalue uses that are safe today, such as
collecting the segments into a container within the same full expression,
so the path-segment test now names the URL it borrows from.

Assisted-by: Claude Code (Claude Opus 5)

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@domenkozar
domenkozar force-pushed the local-pr/url-accessor-lifetime-dcb494e63 branch from 0ed57cc to 79a7d59 Compare August 21, 2026 00:01
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.

2 participants