php / php/php-src

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

Đang mở
#10,082 5 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Category: Engine Feature OS: Windows Status: Needs Triage
Ngôn ngữ chính
C
Star
40.4k
Fork
8.1k
Merge trung bình
2 ngày 13 giờ
Pull request đã merge (30 ngày)
96

Mô tả

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách xác định điểm vào của mô-đun Apache trên Windows, php8apache2_4.dll, và mọi lệnh gọi LoadLibrary hiện có. Xem xét phương pháp DllMain/AddDllDirectory được đề xuất cùng các yêu cầu hỗ trợ Windows 7 của phương pháp này, sau đó xác minh việc tải extension với các bản cài đặt PHP và Apache riêng biệt. Được xem là hoàn tất khi các dependency được tải mà không cần PATH và lỗi liên quan #10076 được giải quyết mà không làm hỏng việc dọn dẹp process.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
c, php
Lĩnh vực
backend, operating-systems, security
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.