mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-21 01:05:45 +00:00
Bug 1434666 - Avoid path aliasing in AppendToLibPath r=rstrong
Previously, it was possible for AppendToLibPath to fail to add the directory /A/B/C/ to LD_LIBRARY_PATH if the directory /A/B/C/D/ was already present. --HG-- extra : rebase_source : 516fb65a57afd97252ad35e52f906b54afdd1616
This commit is contained in:
parent
9897655bb8
commit
04e873a402
@ -382,11 +382,18 @@ AppendToLibPath(const char *pathToAppend)
|
||||
// Leak the string because that is required by PR_SetEnv.
|
||||
char *s = Smprintf("%s=%s", LD_LIBRARY_PATH_ENVVAR_NAME, pathToAppend).release();
|
||||
PR_SetEnv(s);
|
||||
} else if (!strstr(pathValue, pathToAppend)) {
|
||||
// Leak the string because that is required by PR_SetEnv.
|
||||
char *s = Smprintf("%s=%s" PATH_SEPARATOR "%s",
|
||||
LD_LIBRARY_PATH_ENVVAR_NAME, pathToAppend, pathValue).release();
|
||||
PR_SetEnv(s);
|
||||
} else {
|
||||
// Check if pathToAppend is present in pathValue, properly delimited.
|
||||
// For example, if pathValue = "/A/B/C/D" and pathToAppend = "/A/B/C"
|
||||
// then check if ":/A/B/C/D:" contains ":/A/B/C:" (answer: no).
|
||||
char *pathValue_sep = Smprintf(PATH_SEPARATOR "%s" PATH_SEPARATOR, pathValue).get();
|
||||
char *pathToAppend_sep = Smprintf(PATH_SEPARATOR "%s" PATH_SEPARATOR, pathToAppend).get();
|
||||
if (!strstr(pathValue_sep, pathToAppend_sep)) {
|
||||
// Leak the string because that is required by PR_SetEnv.
|
||||
char *s = Smprintf("%s=%s" PATH_SEPARATOR "%s",
|
||||
LD_LIBRARY_PATH_ENVVAR_NAME, pathToAppend, pathValue).release();
|
||||
PR_SetEnv(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user