Repository navigation
fix: treat an empty PGPASSFILE or HOME as unset when reading the password file - #50
Merged
Merged
Conversation
…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>
Member
|
Merged, thank you. An empty |
Contributor
Author
Thank you @VikramLex |
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.
Summary
db::pgpass_passwordusedPGPASSFILEas the password file path even when it was empty, so withPGPASSFILE=""Graphicle looked for a file named""and never read~/.pgpass. A Postgres store whose address has no password then connected without one, whilepsqlwith the same environment reads~/.pgpass.HOMEgave the relative path.pgpass, so the password file was looked up in the current folder.~/.pgpasswhenPGPASSFILEis NULL or empty (fe-connect.c,conn->pgpassfile == NULL || conn->pgpassfile[0] == '\0'), andpqGetHomeDirectoryusesHOMEonly when it is non-empty. The path choice is now a smallpgpass_pathfunction 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
HOMEis empty or unset, libpq falls back to the home folder from the password database (getpwuid); Graphicle still reads no password file then, as onmain. The Windows default (%APPDATA%\postgresql\pgpass.conf) is also unchanged.Test plan
db::tests::password_file_path_treats_empty_environment_values_as_unsetcheckspgpass_pathwith a fake environment:PGPASSFILEset, empty and unset (withHOMEset), andHOMEempty and unset. Withmain's expression inpgpass_paththe empty cases fail (Some("")andSome(".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 warningsandcargo test --locked --all-targetsincrates/graphicle(Rust 1.95.0, macOS). Linux and Windows run in CI.