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:
Arthur Edelstein 2018-02-12 21:46:00 +02:00
Родитель 9897655bb8
Коммит 04e873a402
1 изменённых файлов: 12 добавлений и 5 удалений

Просмотреть файл

@ -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