Skip to content

fix: handle undefined HOME environment variable in key store resolution - #432

Open
Tyagiquamar wants to merge 1 commit into
pyth-network:mainfrom
Tyagiquamar:fix/handle-undefined-home
Open

Tyagiquamar wants to merge 1 commit into
pyth-network:mainfrom
Tyagiquamar:fix/handle-undefined-home

Conversation

@Tyagiquamar

Copy link
Copy Markdown

Resolves #286

Description

When running pyth, pyth_admin, or pythd in environments where the HOME environment variable is undefined (such as minimal Docker containers, AWS Nitro enclaves, or systemd services with DynamicUser=true), attempting to construct std::string(getenv("HOME")) resulted in std::logic_error: basic_string::_M_construct null not valid and aborted the process.

Changes

  1. Added key_store::get_default_dir() helper method that safely inspects getenv("HOME"), falling back to ./.pythd/ when HOME is undefined.
  2. Updated pcapps/pyth.cpp and pcapps/pyth_admin.cpp to evaluate default key directory dynamically instead of initializing static global std::string constants with unchecked getenv("HOME").
  3. Updated pcapps/pythd.cpp get_key_store() to use key_store::get_default_dir().
  4. Added unit test in pctest/test_unit.cpp to verify key_store::get_default_dir() handles both defined and undefined HOME environment variables without throwing.

Verification

  • Built all targets (pc, pyth, pyth_admin, pythd, test_unit) in Linux Docker environment.
  • Executed unit tests (test_unit) with all checks passing.
  • Verified CLI help commands (pyth -h, pyth_admin -h, pythd -h) execute cleanly with HOME undefined.

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.

pythd throws when HOME undefined

1 participant