Skip to content

Fix bugs and improve error handling in emerg-shutdown#359

Open
assisted-by-ai wants to merge 1 commit intoKicksecure:masterfrom
assisted-by-ai:claude/debug-emerg-shutdown-2jYUY
Open

Fix bugs and improve error handling in emerg-shutdown#359
assisted-by-ai wants to merge 1 commit intoKicksecure:masterfrom
assisted-by-ai:claude/debug-emerg-shutdown-2jYUY

Conversation

@assisted-by-ai
Copy link
Copy Markdown

This PR addresses several bugs and improves error handling in the emergency shutdown utility.

Key changes:

  • Remove unused include: Removed #include <stdbool.h> which was not needed
  • Fix console_fd initialization: Changed initial value from 0 to -1 to properly represent an uninitialized file descriptor
  • Fix string length calculation: Removed the + 1 from strlen(str) in the print() function to avoid writing the null terminator
  • Fix memory leak: Added free(arg_copy) when strtok() returns NULL in load_list() to prevent memory leaks on early return
  • Fix separator variable: Changed hardcoded "," to use the sep variable in the second strtok() call for consistency
  • Fix panic key detection logic: Inverted the condition in hw_monitor() to correctly detect when a key group is supported (changed from checking if key is NOT supported to checking if it IS supported)
  • Add missing exit calls: Added exit(0) after kill_system() calls to ensure proper program termination
  • Add input validation: Added null check for arg_part in fifo_monitor() to validate that the timeout value is not empty before parsing it

These changes improve code correctness, prevent resource leaks, and enhance error handling robustness.

https://claude.ai/code/session_016o12KW3j7F1dUBsXBXjfQg

- Fix print() writing NUL terminator to fd (off-by-one in strlen+1)
- Fix load_list() hardcoding "," separator instead of using sep param,
  breaking pipe-separated key alias parsing
- Add missing exit() after kill_system() in paranoid mode and
  --instant-shutdown to prevent fall-through on syscall failure
- Fix memory leak of arg_copy on early return in load_list()
- Fix overly strict device key support check: require any alias per
  group to be supported, not all aliases
- Add NULL check for empty --timeout= value to prevent NULL deref
- Remove duplicate stdbool.h include
- Initialize console_fd to -1 instead of 0 (stdin)

https://claude.ai/code/session_016o12KW3j7F1dUBsXBXjfQg
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.

2 participants