Browse Source

Handle missing or empty environment variables.

Make gfsec-split fallback to $HOME/.config if the XDG_CONFIG_HOME
variable is not set, as gfsec-use already does and as requested by
the XDG Base Directory Specification.

Also apply the fallback if the variable is *defined* but *empty*.

References #6
master
parent
commit
73d290f6a0
  1. 11
      src/gfsec-split.c
  2. 4
      src/gfsec-use.c

11
src/gfsec-split.c

@ -224,8 +224,15 @@ transform_config_pathname(char **cfg, const char *secret)
base = xstrdup(*cfg);
if ( base ) {
xasprintf(cfg, "%s/gfsecret/%s.conf",
getenv("XDG_CONFIG_HOME"), base);
const char *env_info;
if ( (env_info = getenv("XDG_CONFIG_HOME")) && *env_info )
xasprintf(cfg, "%s/gfsecret/%s.conf", env_info, base);
else if ( (env_info = getenv("HOME")) && *env_info )
xasprintf(cfg, "%s/.config/gfsecret/%s.conf", env_info, base);
else
xasprintf(cfg, "%s.conf", base);
free(base);
}
}

4
src/gfsec-use.c

@ -93,9 +93,9 @@ get_config_file_in_dir(const char *filename, char *buffer, size_t len)
int rc;
const char *env_info;
if ( (env_info = getenv("XDG_CONFIG_HOME")) )
if ( (env_info = getenv("XDG_CONFIG_HOME")) && *env_info )
rc = snprintf(buffer, len, "%s/gfsecret/%s.conf", env_info, filename);
else if ( (env_info = getenv("HOME")) )
else if ( (env_info = getenv("HOME")) && *env_info )
rc = snprintf(buffer, len, "%s/.config/gfsecret/%s.conf", env_info, filename);
else {
rc = -1;

Loading…
Cancel
Save