Skip to content

fix use-after-free bug in mkString(Value&, Symbol&) - #74

Closed
spernsteiner wants to merge 1 commit into
NixOS:masterfrom
spernsteiner:master
Closed

spernsteiner wants to merge 1 commit into
NixOS:masterfrom
spernsteiner:master

Conversation

@spernsteiner

Copy link
Copy Markdown
Contributor

The Symbol variant of mkString makes a temporary copy of a std::string from the SymbolTable, then calls c_str() on it and keeps around the resulting pointer, but that pointer becomes invalid as soon as the temporary is destroyed. This change gets rid of the temporary and just calls c_str() directly on the original string.

(Under clang libc++, std::string stores its data on the stack, so it quickly gets overwritten, leading to nasty errors like "invalid character ¿' in name b¿'".)

@edolstra

Copy link
Copy Markdown
Member

Applied, thanks!

@edolstra edolstra closed this Dec 13, 2012
meditans pushed a commit to Ericson2314/nix that referenced this pull request Aug 28, 2020
Test derivations producing git-with-ipfs-refs data
zolodev pushed a commit to zolodev/nix that referenced this pull request Jan 1, 2024
chore(deps): bump sphinx from 3.1.1 to 3.1.2
P-E-Meunier pushed a commit to P-E-Meunier/nix that referenced this pull request Feb 26, 2025
P-E-Meunier pushed a commit to P-E-Meunier/nix that referenced this pull request Feb 26, 2025
ConnorBaker pushed a commit to ConnorBaker/nix that referenced this pull request Jul 25, 2025
…8e087a-ae02-45c0-8bd9-756a89d31008

Release v3.6.1
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 23, 2026
The legacy nix-store --gc, nix-collect-garbage, and modern nix store gc
entry points each hand-rolled the same dispatch: require<GcStore>,
options.pathsToDelete = WholeStore{}, GCResults+Finally, collectGarbage.
Lift the boilerplate into a single helper in src/nix/whole-store-gc.hh
so each call site only needs to set options.action / options.maxFreed
and pass a printer callback.

The opGC printer in nix-store.cc still branches on options.action
(printing live/dead paths vs. printFreed); the helper accepts an
arbitrary printResults callback to preserve that asymmetry. The
printRoots branch in opGC does not run collectGarbage, so it keeps its
local require<GcStore> call.

Refs candidate NixOS#74.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 23, 2026
…batch

Records candidates that landed in this session across four shards;
the libexpr shard already shipped its own doc commit in 43ebd1d.

libfetchers:
  - NixOS#51  -- delete-and-trim github.cc tree-hash scaffolding; trim
            scope expanded past the two #if 0 blocks to also drop
            RefInfo::treeHash, the upstreamTreeHash helper, and the
            treeHash slot in GitArchiveInputScheme::allowedAttrs.
  - NixOS#70  -- close as resolved-by-upstream; commit de6b5f6 (Eelco
            Dolstra, 2025-12-10) extracted makeSourcePathToHashCacheKey
            ahead of the catalog snapshot.

libflake:
  - NixOS#78  -- forEachReachableNode helper covers two of three DFS
            sites (isUnlocked, getAllInputs); doFind excluded as
            structurally different (name-based path-walk via
            follows, InputAttrPath-keyed visited set, throws cycle
            path on revisit).

libutil:
  - NixOS#37  -- fso::descendPath<V> helper covers NarAccessorImpl::find
            only; MemorySourceAccessor::open and
            NarIndexer::createMember excluded after Rule-6 walks
            (one's symlink-rejection policy, the other's amortized
            O(1) parent-stack).
  - NixOS#163 -- additive PipeOptions overload alongside the asymmetric
            originals; replacing the originals would be a
            source-compat break in a shipped header.

nix-cli:
  - NixOS#25  -- reclassify as effectively unimplementable; the
            preprocessor rejects #include directives inside macro
            argument lists, so NIX_COMMAND_DOC("name") with embedded
            #include cannot work.  Effort bumped from trivial to
            medium pending a different mechanism.
  - NixOS#72  -- prependFlakeAttrPaths free helpers; mixin form failed
            on diamond inheritance (SourceExprCommand non-virtually
            inherited via InstallableCommand/InstallableValueCommand).
            Three sites converted; CmdSearch and MixFormatter
            intentionally retain direct overrides.
  - NixOS#74  -- runWholeStoreGC header-only helper across three sites,
            preserving the print-roots branch and the action-aware
            printer.
  - NixOS#75  -- runNarDump header-only template across three sites,
            preserving the legacy "no TTY check" path via a
            checkTTY parameter.
  - NixOS#93  -- three of four NixMultiCommand parents converted to
            getCommandsFor + per-child NIX_REGISTER_COMMAND; CmdHash
            deferred per the candidate.
  - NixOS#141 -- per-command static-ify subset only (deleteOlderThan,
            dryRun in nix-collect-garbage.cc); the candidate's
            nix-instantiate.cc gcRoot/rootNr targets had already
            been folded into a static GcRootNamer.

STATUS.md "Cleanup branches (live)" updated for all five shards
(including libexpr) with new addresses and Local-only tip notes.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 23, 2026
…amends

Two new candidates filed during Pass B reuse review when the
catalog gaps surfaced in the course of landing NixOS#79 and NixOS#85:

  - NixOS#220 (libexpr-extras): prim_path shares the iterateFetcherAttrs
    name-handler-table shape used by the fetcher primops.  Landed
    on vibe-coding/cleanup/libexpr; the helper was renamed
    iterateFetcherAttrs → iterateNamedAttrs and the header
    fetcher-attr-iter.hh → named-attr-iter.hh to drop the
    fetcher-flavoured name.

  - NixOS#221 (libutil-libstore-core-extras): BaseSetting<container<T>>
    parse/to_string/appendOrSet is hand-rolled across six
    specialisations.  Landed on vibe-coding/cleanup/libstore by
    lifting parseStoreReferenceCollection / renderStoreReferenceCollection
    into shipped configuration.hh as parseSettingTokens /
    renderSettingTokens.  Per-T scope notes recorded in the
    candidate body: only the StoreReference pair migrates;
    Strings/StringSet are already one-liners over tokenizeString;
    list/set<path> save one line each (not worth the indirection);
    set<ExperimentalFeature> has irreducible warn-on-unknown
    semantics.

The Pass-B follow-ups also amended:

  - NixOS#51 (libfetchers): unwrap single-field RefInfo struct to Hash;
    bundles the RefInfo deletion into the same delete-and-trim
    commit since the trim made it single-field.
  - NixOS#67 (libexpr): transpose primNumeric's 4×4 string-context
    ladders into a single per-Op NumOpDiag struct so the
    asymmetric "first of the multiplication" wording is visible
    at a glance.
  - NixOS#37, NixOS#163 (libutil): docstring polish (lifetime contract,
    intentionally-not-migrated note, PipeOptions class doc
    rewrite).
  - NixOS#100 (libstore): template forEachConfiguredSigner's printer to
    drop fun<> type erasure.
  - NixOS#135 (libstore): bundle AutoUserLock::acquire's startId/uidCount
    into a UidRange struct.
  - NixOS#74 (nix-cli): template runWholeStoreGC's printer to match
    runNarDump style.

INVENTORY.md catalog total updated 219+44 → 221+44.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 23, 2026
…xOS#221 + final adversarial pass

Extends the most-recent batch entry with:

  - Six Pass-B follow-up amends (categorised after the user asked
    which findings were caused by our changes versus pre-existing
    in source): libfetchers NixOS#51 RefInfo unwrap, libexpr NixOS#67
    NumOpDiag transpose, libutil NixOS#37/NixOS#163 docstring polish,
    libstore NixOS#100 template, libstore NixOS#135 UidRange struct, nix-cli
    NixOS#74 template.

  - Two new candidates filed and landed: NixOS#220 (libexpr,
    iterateFetcherAttrs → iterateNamedAttrs renamed and extended
    to prim_path) and NixOS#221 (libstore → libutil, parseSettingTokens
    / renderSettingTokens lifted into shipped configuration.hh).

  - Final adversarial review pass over those eight changes:
    libfetchers/libstore/nix-cli clean; libutil one minor
    (std::map::insert invalidation overclaim in fso::descendPath
    docstring, fixed); libexpr two minor (NixOS#220 commit body said
    "six-way" but pre-batch had only five attrs; ANSI coloring
    drift on the primop name now passing through %s coloring,
    acknowledged in commit body).

Final tip SHAs updated: libexpr 04f4a67fd, libfetchers 5df2ffc93,
libflake 02b9065c4, libstore 52963ff79, libutil 3e1bc0186, nix-cli
6692dfa88.  All six branches still Local-only past their pushed
tips; push policy is explicit-only.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 23, 2026
Bidirectional traceability audit (Pass-D-aftermath) found four
catalog Branch line texts whose code-description had drifted away
from the actual implementation after the Pass-B follow-up amends:

  - NixOS#100 Branch line: said `forEachConfiguredSigner` extracted
    "using `fun<void(LocalSigner &)>`"; the helper is actually a
    `template<class Callback> static void(const Callback &)`.
  - NixOS#74 Branch line: didn't mention that `runWholeStoreGC` is
    templated on the printer callback type.
  - NixOS#135 Branch line: said `AutoUserLock::acquire` "now takes
    startId/uidCount as plain parameters"; it actually takes a
    single file-local `UidRange` struct.
  - NixOS#51 Branch line: didn't mention that the now-single-field
    `RefInfo` struct itself was unwrapped to use `Hash` directly.

Plus one factual error in the candidate body of NixOS#220 itself: the
opening sentence enumerated a "six-way" chain over
`name`/`path`/`filter`/`recursive`/`sha256`/`method`, but pre-batch
`prim_path` had only five handlers (`method` is computed from the
boolean `recursive` attribute, not as a separate handler). The
commit body of the implementing commit was already corrected; this
fixes the catalog body to match.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 24, 2026
The legacy nix-store --gc, nix-collect-garbage, and modern nix store gc
entry points each hand-rolled the same dispatch: require<GcStore>,
options.pathsToDelete = WholeStore{}, GCResults+Finally, collectGarbage.
Lift the boilerplate into a single helper in src/nix/whole-store-gc.hh
so each call site only needs to set options.action / options.maxFreed
and pass a printer callback.

The opGC printer in nix-store.cc still branches on options.action
(printing live/dead paths vs. printFreed); the helper accepts an
arbitrary printResults callback to preserve that asymmetry. The
printRoots branch in opGC does not run collectGarbage, so it keeps its
local require<GcStore> call.

Refs candidate NixOS#74.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
roberth added a commit to roberth/nix that referenced this pull request Aug 9, 2026
…y; lambda LocalObjects don't need body storage

Two clarifications to the via-Asks design that came up during a
working session and were left implicit before:

1. **Principle NixOS#5 explicitly covers QueryApply.** The flush-time
   substitution that rewrites fact `from` fields per Asks edge
   precondition also rewrites the apply Q's `arg` (and `fn` if
   applicable). The cb-apply itself thus gets a content-defined
   `requestHash` reflecting observations accumulated on its
   constituent subjects, without needing any new hashing scheme.
   Distinct sibling cb invocations land in distinct trie
   positions purely through the existing cidasks machinery.

2. **Lambda LocalObjects don't need their body stored in CAS.**
   The "atom" for a lambda is `(localId, kind=lambda)`; the
   walker reconstructs it as a primop Value whose impl consults
   the AmbientAsks trie on apply, reproducing the recorded
   result for matching arg observations or throwing a depth-2
   divergence signal otherwise. The lambda's application
   behaviour is encoded in the recorded edges and response
   payloads, not in any stored expression body. This sidesteps
   the question of how to serialise arbitrary Nix expressions —
   there's no need.

Both clarifications anchor the depth-2 walker / value-structure
atoms implementation work (tasks NixOS#74, NixOS#75) so the next session
doesn't re-derive them.

Assisted-by: Claude Code (Claude Opus 4.7)
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