PHP on Windows should not rely on PATH for loading its DLL dependencies
Personne n'a encore pris cette issue.
- Langage dominant
- C
- Étoiles
- 40.4k
- Forks
- 8.1k
- Merge moyen
- 2 j 13 h
- PR mergées (30 j)
- 96
Description
There is a longstanding issue with mod_php for Apache when PHP extensions can't be loaded without adding PHP directory to PATH because they rely on some libraries which are in the root PHP directory, and the OS looks for them in the root Apache directory by default. Also, it causes an issue when a user has a few versions of PHP installed (with separate copies of Apache), one of them is in the PATH, and all the others try to load their extensions from that directory in PATH, and fail.
It is possible to resolve this issue by adding the directory of php_mod dll into the list of dll directories of current process. You should use the AddDllDirectory (supported in Windows 7+ since 2011) to specify additional DLL search path. It could be made in the DllMain of the php8apache2_4.dll like this:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <shlwapi.h>
BOOL APIENTRY DllMain(HMODULE hmodule, DWORD dwreason, LPVOID lpreserved)
{
static DLL_DIRECTORY_COOKIE dircookie = nullptr;
switch (dwreason)
{
case DLL_PROCESS_ATTACH:
SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
TCHAR path[MAX_PATH];
if (GetModuleFileName(hmodule, path, MAX_PATH))
{
PathRemoveFileSpec(path);
dircookie = AddDllDirectory(path);
}
break;
case DLL_PROCESS_DETACH:
if (dircookie)
{
RemoveDllDirectory(dircookie);
dircookie = nullptr;
}
break;
}
return TRUE;
}
Another option would be using AddDllDirectory during early initialization and passing LOAD_LIBRARY_SEARCH_DEFAULT_DIRS to every LoadLibrary call.
It makes sense to implement this for better security because a lot of unexpected things can be in PATH and load instead of what was expected. It will also resolve issues like #10076. This issue was already discussed in the mailing list and Christoph M. Becker agreed that it is OK to include such change.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par localiser le point d’entrée du module Apache pour Windows, php8apache2_4.dll, ainsi que tous les appels existants à LoadLibrary. Examinez l’approche DllMain/AddDllDirectory proposée et ses exigences de prise en charge de Windows 7, puis vérifiez le chargement des extensions avec des installations séparées de PHP et d’Apache. Le travail est terminé lorsque les dépendances se chargent sans PATH et que l’échec associé #10076 est résolu sans perturber le nettoyage du processus.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- c, php
- Domaine
- backend, operating-systems, security
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100