standard/syslog: the request shutdown hook calls closelog() even when the request never opened syslog
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- Nửa ngày
- Mức phù hợp với người mới
- 62/100
Hướng nghiên cứu
Lệnh đóng vô điều kiện nằm trong PHP_RSHUTDOWN_FUNCTION(syslog) trong ext/standard/syslog.c. Hãy đọc php_closelog() và cờ PG(have_called_openlog) trong main/php_syslog.c (khoảng dòng 74-84), cùng với phần đặt lại trong main/main.c gần dòng 2317. Việc được coi là xong khi một yêu cầu không bao giờ gọi openlog, closelog hay syslog bỏ qua php_closelog() nhưng vẫn giải phóng BG(syslog_device). Hãy kiểm tra bằng strace qua nhiều yêu cầu trong một SAPI đa yêu cầu, như issue đã nêu.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
ext/standard/syslog.c installs an unconditional request shutdown hook:
PHP_RSHUTDOWN_FUNCTION(syslog)
{
php_closelog();
if (BG(syslog_device)) {
free(BG(syslog_device));
BG(syslog_device) = NULL;
}
return SUCCESS;
}
php_closelog() runs after every request, whether or not this request opened syslog. In a SAPI that serves more than one request per process, that closes a process-wide handle the request may not own, and the next request opens it again.
Note that the state to avoid this already exists: php_openlog() sets PG(have_called_openlog) = 1 and php_closelog() clears it (main/php_syslog.c:74-84), and php_module_startup() resets it to 0 (main/main.c:2317). The shutdown hook simply does not look at it.
Expected
A request that never calls openlog(), closelog() or syslog() should leave the process syslog handle alone. If the handle was opened outside PHP, for example by the embedding application or by a library in the same process, PHP should not close it.
Actual
Embedded SAPI, PHP 8.5.11 (Alpine 3.24.2, musl 1.2.6, OpenSSL 3.5.9), one worker process serving three requests with error_log = syslog and a script that only calls error_log("request"). strace of the worker:
1080 connect(15, {sa_family=AF_UNIX, sun_path="/dev/log"}, 12) = 0
1080 sendto(15, "<13>Oct 13 21:57:46 php: request\n", 33, 0, NULL, 0) = 33
1080 connect(14, {sa_family=AF_UNIX, sun_path="/dev/log"}, 12) = 0
1080 sendto(14, "<13>Oct 13 21:57:46 php: request\n", 33, 0, NULL, 0) = 33
1080 connect(14, {sa_family=AF_UNIX, sun_path="/dev/log"}, 12) = 0
1080 sendto(14, "<13>Oct 13 21:57:46 php: request\n", 33, 0, NULL, 0) = 33
Three requests, three connects: the handle does not survive a request boundary. In the same process, a host that opened syslog before running PHP loses it when the first request ends. php-fpm works around this by calling php_closelog() itself when it takes over the child, with the comment "ensure to close syslog not to interrupt with PHP syslog code" (sapi/fpm/fpm/fpm_stdio.c:144), which is the same interaction seen from the other side.
Suggested fix
Check the existing flag before closing:
PHP_RSHUTDOWN_FUNCTION(syslog)
{
if (PG(have_called_openlog)) {
php_closelog();
}
...
}
That keeps the per-request BG(syslog_device) cleanup, closes the handle when this request opened it, and leaves a host-owned handle alone.
Version
PHP 8.5.11, and the same code is in the current PHP-8.5 and master branches.
- Ngôn ngữ chính
- C
- Star
- 40.4k
- Fork
- 8.2k
- Merge trung bình
- 2 ngày 24 phút
- Pull request đã merge (30 ngày)
- 157
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của php/php-src
-
Bug Status: Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
php/php-src#24196 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Feature Status: Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
php/php-src#24183 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Sockets from synchronous stream_socket_client() are left in non-blocking mode on WindowsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởBug Status: Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày
-
sapi_lsapi_ub_write does not return bytes written in lsapi modeCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởBug Status: Needs Triage
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug Status: Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
UB: (int) cast of a user double outside int range in dispatch / vm_index_is_int / flat_index_atĐang mởarea:runtime-vm
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
InauguralSystems/EigenScript#1748 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
chore: update release scheduleĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
foomatic-rip: dstrtrim_right() underflows mid-loop on an all-whitespace stringCó thể đã có người làm @ManasBagul23 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
OpenPrinting/cups-filters#759 ·
Maintainer thường phản hồi trong vòng 11 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
EchoTools/nevr-runtime#547 ·
Maintainer thường phản hồi trong vòng 1 ngày