PHP on Windows should not rely on PATH for loading its DLL dependencies
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- C
- Estrellas
- 40.4k
- Forks
- 8.1k
- Merge medio
- 2 d 13 h
- PR fusionados (30 d)
- 96
Descripción
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza localizando el punto de entrada del módulo de Apache para Windows, php8apache2_4.dll, y cualquier llamada existente a LoadLibrary. Revisa el enfoque propuesto de DllMain/AddDllDirectory y sus requisitos de compatibilidad con Windows 7; después, verifica la carga de extensiones con instalaciones separadas de PHP y Apache. Se considera terminado cuando las dependencias se cargan sin PATH y se resuelve el fallo relacionado #10076 sin romper la limpieza del proceso.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- c, php
- Área
- backend, operating-systems, security
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100