Skip to content

Fix sorting logic and clean up redundant conditionals#6

Open
assisted-by-ai wants to merge 1 commit 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 1 commit 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

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.

Comment thread etc/grub.d/10_20_linux_live Outdated
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.)

- 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
@assisted-by-ai assisted-by-ai force-pushed the claude/bug-fixes-aySbJ branch from 0d5b480 to 273d0d0 Compare April 27, 2026 18:21
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