fix(defense): route errors to stderr, guard cd/link, portable read#57
Merged
Conversation
Low-severity error-handling and portability cleanups: - defense.zsh: send the 'docker not installed' / 'no compose file' / mkcase usage / gocase 'no cases dir' messages to stderr (>&2) instead of stdout, and in gocase cd before exporting $CASE with `|| return 1` so a failed cd can't leave the env var dangling. (Parity with Kali's offensive.zsh.) - bootstrap.sh: check the `ln -s` exit code in link() so a failed symlink is visible, and declare the wire_links loop var `local f` so it doesn't leak. - detections/siem/gen-siem.sh: replace `mapfile` (bash 4+) with a while-read loop so the SIEM generator runs on macOS's stock bash 3.2. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MbS29qHuYaG2AUnmXkKD96
There was a problem hiding this comment.
Pull request overview
This PR makes small, targeted shell portability and error-handling improvements across the Defense dotfiles tooling, aligning runtime behavior with the stated “distro-agnostic” goal and making failures/usage errors surface correctly.
Changes:
- Route several user-facing error/usage messages in
defense/defense.zshto stderr and hardengocaseby guardingcdbefore exportingCASE. - Make
bootstrap.sh’slink()report symlink failures explicitly and preventwire_links’ loop variable from leaking into the caller scope. - Update
detections/siem/gen-siem.shto avoidmapfile(bash 4+) in favor of a bash 3.2-compatiblewhile readloop for macOS compatibility.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| detections/siem/gen-siem.sh | Replaces mapfile with a portable read loop to support macOS bash 3.2 while preserving deterministic ordering. |
| defense/defense.zsh | Sends key error/usage messages to stderr and ensures gocase only exports CASE after a successful cd. |
| bootstrap.sh | Surfaces ln -s failures via stderr + non-zero return and scopes wire_links loop var with local. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Review parity with Kali's mkengagement: both the 'already exists' fast-path and the create path now cd (guarded with || return 1) before exporting $CASE, so a failed cd can't leave the env var pointing where the shell isn't. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MbS29qHuYaG2AUnmXkKD96
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Low-severity error-handling and portability cleanups from the fleet static-analysis audit.
defense/defense.zsh— send thedocker not installed/no compose file/mkcaseusage /gocase"no cases dir" messages to stderr (>&2) instead of stdout, and ingocasecdbefore exporting$CASEwith|| return 1. Brings Defense in line with Kali'soffensive.zsh.bootstrap.sh— check theln -sexit code inlink()so a failed symlink is visible, and declare thewire_linksloop varlocal fso it doesn't leak into the caller shell.detections/siem/gen-siem.sh— replacemapfile(bash 4+) with awhile readloop so the SIEM generator runs on macOS's stock bash 3.2 (Defense is distro-agnostic).Verification
bash -nclean onbootstrap.shandgen-siem.sh;.zshvalidated byzsh -nin CI.🤖 Generated with Claude Code
Generated by Claude Code