Skip to content

fix: treat an empty PGPASSFILE or HOME as unset when reading the password file - #50

Merged
VikramLex merged 1 commit into
Graphicle-AI:mainfrom
leninworld:fix-empty-pgpassfile
Nov 27, 2026
Merged

VikramLex merged 1 commit into
Graphicle-AI:mainfrom
leninworld:fix-empty-pgpassfile

Conversation

@leninworld

Copy link
Copy Markdown
Contributor

Summary

  • db::pgpass_password used PGPASSFILE as the password file path even when it was empty, so with PGPASSFILE="" Graphicle looked for a file named "" and never read ~/.pgpass. A Postgres store whose address has no password then connected without one, while psql with the same environment reads ~/.pgpass.
  • An empty HOME gave the relative path .pgpass, so the password file was looked up in the current folder.
  • libpq treats both as unset: it uses the default ~/.pgpass when PGPASSFILE is NULL or empty (fe-connect.c, conn->pgpassfile == NULL || conn->pgpassfile[0] == '\0'), and pqGetHomeDirectory uses HOME only when it is non-empty. The path choice is now a small pgpass_path function with the empty-value filter the program already uses for its other variables. A non-empty value is still used as given.

Not changed: when HOME is empty or unset, libpq falls back to the home folder from the password database (getpwuid); Graphicle still reads no password file then, as on main. The Windows default (%APPDATA%\postgresql\pgpass.conf) is also unchanged.

Test plan

  • db::tests::password_file_path_treats_empty_environment_values_as_unset checks pgpass_path with a fake environment: PGPASSFILE set, empty and unset (with HOME set), and HOME empty and unset. With main's expression in pgpass_path the empty cases fail (Some("") and Some(".pgpass")), and removing either filter fails its own case; with this change it passes.
  • cargo fmt --check, cargo clippy --locked --all-targets -- -D warnings, cargo clippy --locked --all-targets --features local-inference -- -D warnings and cargo test --locked --all-targets in crates/graphicle (Rust 1.95.0, macOS). Linux and Windows run in CI.

…word file

An empty PGPASSFILE made pgpass_password look for a password file named
"" instead of ~/.pgpass, and an empty HOME made it read .pgpass from the
current folder. libpq treats both as unset: an empty PGPASSFILE means the
default ~/.pgpass, and an empty HOME is never used as the home folder.

Signed-off-by: Lenin Mookiah <2639584+leninworld@users.noreply.github.com>
@VikramLex
VikramLex merged commit b1f700b into Graphicle-AI:main Nov 27, 2026
13 of 14 checks passed
@VikramLex

Copy link
Copy Markdown
Member

Merged, thank you. An empty PGPASSFILE or HOME now counts as unset when Graphicle looks for the password file, as libpq does, and the pgpass_path split makes the test clean. The one failing check (the macOS write-ahead-log test) is a known timing issue on main, unrelated to this change; the next release fixes it. This will ship in 0.1.20.

@leninworld

Copy link
Copy Markdown
Contributor Author

Merged, thank you. An empty PGPASSFILE or HOME now counts as unset when Graphicle looks for the password file, as libpq does, and the pgpass_path split makes the test clean. The one failing check (the macOS write-ahead-log test) is a known timing issue on main, unrelated to this change; the next release fixes it. This will ship in 0.1.20.

Thank you @VikramLex

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