Skip to content

Fix sorting logic and clean up redundant conditionals#6

Open
assisted-by-ai wants to merge 3 commits intoKicksecure:masterfrom
assisted-by-ai:claude/bug-fixes-aySbJ
Open

Fix sorting logic and clean up redundant conditionals#6
assisted-by-ai wants to merge 3 commits intoKicksecure:masterfrom
assisted-by-ai:claude/bug-fixes-aySbJ

Conversation

@assisted-by-ai
Copy link
Copy Markdown

Summary

This PR fixes several bugs and improves code clarity across the grub-live hardening scripts and GRUB configuration files.

Key Changes

usr/libexec/grub-live/live-hardener:

  • Fixed incorrect comment describing STX character sorting behavior (changed "sorts higher" to "sorts before" and clarified it has the second-lowest byte value)
  • Fixed control code references in comments (SOH → STX) to match actual implementation
  • Added stripping of trailing newline from proc_mount_annotated_str to prevent sort from creating ghost empty elements
  • Removed duplicate variable declaration allow_hide_submounts in local variable list
  • Added guard to skip empty entries in lsblk_raw_path_list caused by trailing newline escapes
  • Added early return when overlay_mount_list_str is empty to avoid unnecessary processing
  • Added missing break statement when skip_dir_overlay is true to prevent redundant directory traversal

etc/grub.d/10_20_linux_live and etc/grub.d/10_60_linux_live_advanced:

  • Simplified redundant conditional logic that checked multiple conditions but assigned the same value in all branches
  • Changed GRUB_DISTRIBUTOR assignment to directly use grub_distributor_appendix instead of conditional checks
  • Updated distributor string from "disposable use" to "For disposable use" for better grammar

etc/grub.d/45_debugging:

  • Fixed parameter expansion in echo statements from $@ to $* for proper quoting behavior

Notable Implementation Details

  • The sorting fix ensures mount paths are correctly ordered by replacing forward slashes with STX (ASCII 0x02) which has a lower byte value than typical path characters, guaranteeing correct sort order in C locale
  • The trailing newline stripping prevents sort from interpreting empty lines as valid mount entries
  • The simplified conditionals reduce code duplication while maintaining identical functionality

https://claude.ai/code/session_01WHDK9nRRjJnnUtUUBswH1D

claude added 3 commits April 10, 2026 09:34
- Fix empty mount list edge case in live-hardener where readarray on an
  empty here-string creates a ghost array element, causing harden_mounts
  to attempt operations on an empty mount path
- Fix inconsistent grub_distributor_appendix text between 10_20_linux_live
  ("disposable use") and 10_60_linux_live_advanced ("For disposable use")
- Remove dead conditional branches in both GRUB scripts where all
  if/elif/else branches assigned GRUB_DISTRIBUTOR to the same value
- Use $* instead of $@ in 45_debugging output() to avoid
  implementation-defined behavior when embedded in a double-quoted string

https://claude.ai/code/session_01WHDK9nRRjJnnUtUUBswH1D
- Fix ghost empty first element in proc_mount_path_list (and sibling
  arrays): the while loop in populate_proc_mount_lists appends a
  trailing newline to proc_mount_annotated_str, and the here-string
  adds another; sort sees the resulting empty line and places it first
  in C locale, creating a spurious empty element at index 0. Fix by
  stripping the trailing newline before sorting.
- Fix ghost empty entry in lsblk_path_list when parsing multi-mount
  devices: lsblk encodes newline-separated mount paths with trailing
  \x0a, which after printf %b decoding and readarray via here-string
  produces a trailing empty array element. Fix by skipping empty
  entries in the lsblk path loop.
- Fix misleading comment that described STX as having the
  "second-highest sorting order" in C locale; STX (0x02) actually has
  one of the lowest byte values, meaning it sorts earliest.

https://claude.ai/code/session_01WHDK9nRRjJnnUtUUBswH1D
- Fix comment that says slashes are replaced with "SOH" when the code
  actually uses STX (ascii_stx). SOH is used as the decorator/line
  separator, not for slash replacement.
- Remove duplicate variable declarations in get_mount_list_to_harden:
  submount_dir was declared on lines 253 and 254, and
  allow_hide_submounts was declared twice on line 254.
- Add missing early break in the nooverlay filesystem check: when
  skip_dir_overlay is set to 'true' by the inner loop, only the inner
  loop breaks; the outer loop over proc_mount_path_list continues
  iterating needlessly over all remaining mount entries.

https://claude.ai/code/session_01WHDK9nRRjJnnUtUUBswH1D
Copy link
Copy Markdown

@ArrayBolt3 ArrayBolt3 left a comment

Choose a reason for hiding this comment

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

Accepted in ArrayBolt3@1fb6160 with an added comment and a couple of string changes.

else
GRUB_DISTRIBUTOR="$grub_distributor_appendix"
fi
grub_distributor_appendix="LIVE Mode | USER Session | For disposable use"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

"For" should not be added to "disposable use". (It was mistakenly present in a different script in this repo, which is probably why Claude decided to add it here.)

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