Skip to content

Preserve GUM environment records during factory-reset elevation - #13316

Merged
ryanrhughes merged 6 commits into
omacom:quattrofrom
AFOliveira:fix/factory-reset-gum-records-20260926
Nov 1, 2026
Merged

ryanrhughes merged 6 commits into
omacom:quattrofrom
AFOliveira:fix/factory-reset-gum-records-20260926

Conversation

@AFOliveira

@AFOliveira AFOliveira commented Sep 26, 2026 •

Copy link
Copy Markdown
Member

Factory reset now forwards the caller's GUM_* styling through sudo as whole NUL-delimited records, so a newline in any exported variable can't change what env runs as root.

The old forwarding split env output on newlines and kept every line starting with GUM_. That truncated a multiline GUM_* value, and a newline inside some other variable could hand sudo env a stray GUM_ line. A directory name in PWD is enough for that, and a line without = is a command word to env, so it would run in place of the reset.

Now the records come from env -0 | grep -z '^GUM_[A-Za-z0-9_]*=', so only real GUM_* assignments are forwarded, each one exact, and env -- ends option parsing before them.

Verified:

  • test/shell.d/factory-reset-elevation-test.sh passes, and fails with the old record parsing put back (with or without --)
  • With a stub sudo, a newline in PWD reached env as a command on the old code and was dropped on the new code
  • The theme's single-line GUM_* values and the no-GUM_* case forward exactly as before
  • Startup and account-cleanup fixtures plus the CLI suite passed in a disposable Omarchy VM

Reported by Sean Huber.

@llstrk

llstrk commented Sep 27, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Verified at 8f782773: no functional regression found in the tested scope. The startup guard, the packaged-path elevation and the NUL-delimited GUM_* forwarding behave as described. The notes below are documentation, message wording and coordination items.

Verified: record boundaries. A stub sudo recorded the env arguments it was given (a separate environment dump of the elevated command, with the stub clearing the environment like env_reset, confirmed the multiline case):

Caller environment Base d3cfd53b Head 8f782773
GUM_A=$'line1\nline2' GUM_A=line1 (truncated) GUM_A=line1\nline2 (exact, one argument)
NOTE=$'x\nGUM_cmd' (non-GUM) env runs GUM_cmd as the command, exit 127 not forwarded
NOTE=$'a\nGUM_INJECT=1' (non-GUM) GUM_INJECT=1 injected not forwarded
GUM_B= (empty) GUM_B= (exact) GUM_B= (exact)

Values containing =, a leading -, quotes or $(...) also arrive as single exact assignments at head, and nothing in them is executed.

Verified: launch forms. For a copy identical to the installed command, absolute, relative, symlinked, bash <path> and sourced non-root launches all elevate /usr/bin/omarchy-system-factory-reset with arguments intact. A copy that differs from the installed command exits 1 before calling sudo. As root (simulated with a user namespace), a differing copy exits 1 before the reset body, while the installed copy reaches it. On a standard install the guard compares the installed file with itself (from source), so the elevation target matches the base. A missing or unreadable installed command, or a missing /usr/bin/cmp, also refuses (fails closed).

Verified: test. factory-reset-elevation-test.sh passes on head, directly and through test/shell, and reports a skip (exit 0) when user namespaces are unavailable. It fails when any of these production changes is reverted on its own: the guard, the packaged path, the env -0/grep -z records, or --. It also fails on the merge base and on #13047's head. The narrower ^GUM_[A-Za-z0-9_]*= pattern is not covered, with no observable effect, since bash does not export invalid names.

Dev-link help still says sudo runs the checkout

The guard also refuses a differing checkout copy under sudo or as root, where nothing would be replaced. The effective rule is "only the installed reset runs", which docs/file-layout.md states. bin/omarchy-dev-link still describes the older contract, and the new guard comment is narrower than the code:

  • The comment above the guard (bin/omarchy-system-factory-reset:38) covers only the non-root handoff.
  • bin/omarchy-dev-link says root stays "on the code being edited" (lines 17-22) and that sudo resolves omarchy-* from the checkout (help text, lines 44-46), and it prints sudo now resolves omarchy-* from <checkout>/bin (line 118).

Impact: on a dev-linked machine, sudo omarchy-system-factory-reset resolves to the checkout and is refused whenever the checkout copy differs from the installed one, which the dev-link help does not mention.

Suggested change: if the stricter rule is intended, state it in the guard comment and note the factory-reset exception in the omarchy-dev-link help and output. #12883 also rewrites that help text and output line.

Refusal message: the message could name the way out on a dev-linked machine: a package build from the linked checkout (omarchy dev pkg-test <package> <checkout>; the package recipe installs bin/* unchanged, so the installed copy should then match) or omarchy dev unlink. It also appears when the installed command is missing or unreadable, because cmp -s suppresses its own error, and after bash's "No such file or directory" when /usr/bin/cmp is missing. In those cases the message points at a version mismatch that is not the cause. A separate message for comparator errors would be clearer. test/shell.d/factory-reset-elevation-test.sh:80 checks the current wording.

Description: empty GUM_* values already survived at the base (table above). The functional fix is for multiline values and record boundaries.

Optional test improvement: if the export PATH= marker ever disappears, the awk at lines 15-19 ends the test through set -e with no not ok line. Appending || fail "startup marker 'export PATH=' not found" would name the cause. This fails closed today: the untruncated copy it writes is never made executable or run.

Coordination: #13047 is fully contained in this PR. #10219 edits the same startup lines, and a three-way merge conflicts in the elevation block. Its root ExecStart=/usr/bin/omarchy-system-factory-reset --unattended passes the new guard. #12883 inserts a different paragraph at the same point in docs/file-layout.md (a three-way merge conflicts), and both paragraphs can be kept.


Review information

Test scope: Source review of the full PR diff (including #13047's commits) against merge base d3cfd53b and quattro at c5b4db77, plus omarchy-dev-link, callers of the reset and the published package recipe. In an isolated sandbox, only startup-truncated copies of the script ran, with a stub sudo (plus the existing factory-reset-accounts-test.sh, which extracts functions only): the PR test (directly and through test/shell), revert mutants, launch-form and environment-forwarding cases. Root cases used a user namespace. Real sudo, real root, Btrfs and the full reset were not run. sudo's handling of env -- ... is taken from its documentation.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@omarchybot omarchybot added the bug Something isn't working label Oct 3, 2026
@ryanrhughes
ryanrhughes merged commit 3e42525 into omacom:quattro Nov 1, 2026
ryanrhughes pushed a commit that referenced this pull request Nov 1, 2026
* Pin factory-reset elevation to the packaged command

Use the installed executable for non-root self-elevation, including calls from a development checkout or symlink.

Reported-by: Aleksej <aleksejhairov@yandex.ru>

* Test factory-reset elevation paths and arguments

* Refuse factory reset handoff to a different installed version

* Test factory reset version mismatches and packaged invocation

* Preserve GUM environment records during reset elevation

Reported-by: Sean Huber

* Test GUM record boundaries in reset elevation

(cherry picked from commit 3e42525)
@emirb emirb added this to the 4.5 milestone Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants