Skip to content

cask/audit: fix nil crash in min_os check#23268

Merged
MikeMcQuaid merged 1 commit into
mainfrom
brew-audit-min-os-nil-guard
Jul 22, 2026
Merged

cask/audit: fix nil crash in min_os check#23268
MikeMcQuaid merged 1 commit into
mainfrom
brew-audit-min-os-nil-guard

Conversation

@krehel

@krehel krehel commented Jul 22, 2026

Copy link
Copy Markdown
Member

  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do? Performance claims (e.g. "this is faster") must include Hyperfine benchmarks.
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

  • AI was used to generate or assist with generating this PR.

I identified the crash when working on the lm-studio cask, debugged with Opus 4.8 and tested both by Opus and by hand. Tests run using brew lgtm --online


audit_min_os compares depends_on_min_os and cask_min_os against HOMEBREW_MACOS_OLDEST_ALLOWED without nil guards. Both are nil for a cask with no depends_on macos: and no versioned on_system block, so when the artifact's minimum macOS exceeds the floor the audit raises undefined method '>' for nil (reported as "exception while auditing ") instead of the intended "cask declared no minimum macOS version" error.

macOS-only casks declare a minimum OS requirement using the depends_on macos: syntax, so the nil path was only exposed by cross-platform casks that scope macOS artifacts in an on_macos block and declare no macOS version.

This guards the nil cases so the audit doesn't crash and add a regression test for an app requiring a newer macOS with no declared minimum.

`audit_min_os` compares `depends_on_min_os` and `cask_min_os` against
`HOMEBREW_MACOS_OLDEST_ALLOWED` without nil guards. Both are nil for a
cask with no `depends_on macos:` and no versioned on_system block, so
when the artifact's minimum macOS exceeds the floor the audit raises
`undefined method '>' for nil` (reported as "exception while auditing
<cask>") instead of the intended "cask declared no minimum macOS
version" error.

macOS-only casks always declare a minimum OS requirement using the
`depends_on macos:` syntax, so the nil path was only exposed by
cross-platform casks that scope macOS artifacts in an `on_macos` block
and declare no macOS version.

This guards the nil cases so the audit doesn't crash and add a
regression test for an app requiring a newer macOS with no declared
minimum.
Copilot AI review requested due to automatic review settings July 22, 2026 12:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a crash in Cask::Audit’s minimum macOS version audit when a cask has neither a depends_on macos: stanza nor a versioned on_system minimum, ensuring the audit reports the intended error instead of raising an exception.

Changes:

  • Add nil guards around depends_on_min_os/cask_min_os comparisons and logging in audit_min_os.
  • Add a regression spec covering a macOS-scoped artifact with no declared minimum macOS version, where the artifact requires a newer macOS.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
Library/Homebrew/cask/audit.rb Adds nil-safe handling in audit_min_os to prevent nil > ... crashes and keep the audit reporting a proper error.
Library/Homebrew/test/cask/audit_spec.rb Adds a regression test for the nil-minimum-OS path to ensure the audit errors cleanly instead of crashing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@MikeMcQuaid MikeMcQuaid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@MikeMcQuaid
MikeMcQuaid added this pull request to the merge queue Jul 22, 2026
Merged via the queue into main with commit 383f614 Jul 22, 2026
43 checks passed
@MikeMcQuaid
MikeMcQuaid deleted the brew-audit-min-os-nil-guard branch July 22, 2026 13:34
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.

3 participants