Skip to content

fix: prevent "permission denied" errors from empty hook handlers #729

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nicksherron
Copy link

Fixes #728

Summary

This PR fixes the "permission denied: " errors that occur when zinit tries to execute empty hook handlers from annexes.

Problem

When loading certain annexes, zinit attempts to execute hook handlers that may be empty or undefined. This results in the shell trying to execute an empty command, which produces "permission denied: " errors:

.zinit-load:25: permission denied:
.zinit-load-snippet:63: permission denied:

Solution

Added checks to ensure hook handlers are non-empty before attempting to execute them:

  1. In .zinit-load() function: Check if ${___arr[5]} is non-empty before execution
  2. In .zinit-load-snippet() function: Check if ${arr[5]} is non-empty before execution

Changes

  • Modified zinit.zsh:
    • Added conditional check in .zinit-load() at line 1650
    • Added conditional check in .zinit-load-snippet() at line 1446
  • Added comprehensive tests in tests/empty-hook-handler.zunit to ensure:
    • Empty handlers don't cause errors
    • Valid handlers still execute normally
    • Mixed scenarios work correctly

Testing

  1. Manual testing confirmed the fix resolves the issue
  2. Added automated tests that verify:
    • Empty hook handlers in ZINIT_EXTS don't cause errors
    • Empty hook handlers in ZINIT_EXTS2 don't cause errors
    • Empty snippet hook handlers don't cause errors
    • Valid hook handlers continue to work as expected
    • Mixed scenarios with both empty and valid handlers work correctly

Backwards Compatibility

This change is fully backwards compatible. It only adds a safety check and doesn't change any existing behavior for valid hook handlers.

Related Issues

This issue has been reported by multiple users experiencing "permission denied" errors when using zinit annexes.

Add checks to ensure hook handlers are non-empty before execution in
both .zinit-load() and .zinit-load-snippet() functions. This prevents
the shell from attempting to execute empty commands which results in
"permission denied: " errors.

The issue occurs when ZINIT_EXTS or ZINIT_EXTS2 arrays contain entries
where the 5th element (the handler function) is empty or undefined.

This addresses the issue described in zdharma-continuum#728
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug]: Empty hook handlers cause "permission denied" errorsqq
1 participant