bug: prevent lightcontrol from crashing without values#90
Open
ALX99 wants to merge 4 commits into
Open
Conversation
5cf571d to
dd748db
Compare
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.
Bug
Running
.local/bin/lightcontrol -dor.local/bin/lightcontrol -swithout the required value crashes under Bash strict mode instead of reporting a usage error.Severity and impact
This is a reliability bug in a user-facing brightness helper. Omitting a required value is a realistic command-line mistake. The script should fail before touching backlight state and tell the user how to call it; instead it exposes a shell
unbound variablecrash.Evidence
Relevant files and lines on
master:.local/bin/lightcontrol: line 4 enables Bash strict mode withset -eou pipefail..local/bin/lightcontrol: lines 44-47 handle-d, runshift, then calldelta_change "$1"without verifying that a value remains..local/bin/lightcontrol: lines 49-52 handle-s, runshift, then callset_brightness "$1"without verifying that a value remains.Observed incorrect behavior from the baseline pattern:
That is deterministic for both missing-value option paths: after
shift,$1is unset, andset -uaborts before the script can produce an intentional error.Reproduce
Setup:
Triggering condition: pass
-dor-swithout its required value.Exact commands:
Actual result on
master:Expected result:
The commands should exit non-zero without reaching brightness reads or writes.
Root cause
The option handlers assume
shiftleaves an operand in$1. Underset -u, dereferencing$1after a missing operand is a runtime error.Fix
The fix adds a small
require_valueguard used by both-dand-saftershift. Missing operands now print the existing usage text and exit before any brightness calculation or write is attempted.Validation
Commands run and results:
Regression test added:
tests/lightcontrol-missing-value.test.shverifies both-dand-swithout values fail, do not printunbound variable, and do print the usage text.Additional repository-scope check:
Scope
Intentionally not changed:
-d VALUEand-s VALUEbehavior,