php / php/php-src

PHP on Windows should not rely on PATH for loading its DLL dependencies

Offen
#10,082 5 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Category: Engine Feature OS: Windows Status: Needs Triage
Vorherrschende Sprache
C
Sterne
40.4k
Forks
8.1k
Ø Merge
2 T. 13 Std.
Gemergte PRs (30 T.)
96

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, den Einstiegspunkt des Windows-Apache-Moduls, php8apache2_4.dll, und alle vorhandenen LoadLibrary-Aufrufe zu lokalisieren. Prüfe den vorgeschlagenen DllMain/AddDllDirectory-Ansatz und seine Anforderungen an die Unterstützung von Windows 7 und verifiziere anschließend das Laden von Erweiterungen mit getrennten PHP- und Apache-Installationen. Erledigt ist die Aufgabe, wenn Abhängigkeiten ohne PATH geladen werden und der zugehörige Fehler #10076 behoben ist, ohne die Prozessbereinigung zu beeinträchtigen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
c, php
Bereich
backend, operating-systems, security
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.