Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main: Handle empty HOME, HOMEDRIVE, and HOMEPATH envvar #2385

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions main/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -3522,7 +3522,7 @@ static char* prependEnvvar (const char *path, const char* envvar)
char *full_path = NULL;

const char* const envval = getenv (envvar);
if (envval)
if (envval && strlen (envval))
full_path = combinePathAndFile(envval, path);

return full_path;
Expand All @@ -3544,9 +3544,11 @@ static char *getConfigAtHomeOnWindows (const char *path,
vStringCatS (windowsHome, homeDrive);
vStringCatS (windowsHome, homePath);

char *tmp = combinePathAndFile (vStringValue(windowsHome), path);
vStringDelete (windowsHome);
char *tmp = vStringIsEmpty (windowsHome)
? NULL
: combinePathAndFile (vStringValue(windowsHome), path);

vStringDelete (windowsHome);
return tmp;
}
return NULL;
Expand Down
16 changes: 10 additions & 6 deletions main/routines.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,14 +714,18 @@ extern char *combinePathAndFile (
const char *const path, const char *const file)
{
vString *const filePath = vStringNew ();
const int lastChar = path [strlen (path) - 1];
bool terminated = isPathSeparator (lastChar);
size_t len = strlen (path);

vStringCopyS (filePath, path);
if (! terminated)
vStringPut (filePath, OUTPUT_PATH_SEPARATOR);
vStringCatS (filePath, file);
if (len)
{
const int lastChar = path [len - 1];
bool terminated = isPathSeparator (lastChar);
vStringCopyS (filePath, path);
if (! terminated)
vStringPut (filePath, OUTPUT_PATH_SEPARATOR);
}

vStringCatS (filePath, file);
return vStringDeleteUnwrap (filePath);
}

Expand Down