mirror of
https://github.com/php/frankenphp.git
synced 2026-03-24 00:52:11 +01:00
fix: prevent crash when calling apache_request_headers() in non-HTTP context
This commit is contained in:
@@ -250,7 +250,7 @@ PHP_FUNCTION(frankenphp_request_headers) {
|
||||
|
||||
frankenphp_server_context *ctx = SG(server_context);
|
||||
struct go_apache_request_headers_return headers =
|
||||
go_apache_request_headers(ctx->current_request);
|
||||
go_apache_request_headers(ctx->current_request, ctx->main_request);
|
||||
|
||||
array_init_size(return_value, headers.r1);
|
||||
|
||||
|
||||
@@ -582,7 +582,18 @@ func go_register_variables(rh C.uintptr_t, trackVarsArray *C.zval) {
|
||||
}
|
||||
|
||||
//export go_apache_request_headers
|
||||
func go_apache_request_headers(rh C.uintptr_t) (*C.go_string, C.size_t, C.uintptr_t) {
|
||||
func go_apache_request_headers(rh, mrh C.uintptr_t) (*C.go_string, C.size_t, C.uintptr_t) {
|
||||
if rh == 0 {
|
||||
// worker mode, not handling a request
|
||||
mr := cgo.Handle(mrh).Value().(*http.Request)
|
||||
mfc := mr.Context().Value(contextKey).(*FrankenPHPContext)
|
||||
|
||||
if c := mfc.logger.Check(zap.DebugLevel, "apache_request_headers() called in non-HTTP context"); c != nil {
|
||||
c.Write(zap.String("worker", mfc.scriptFilename))
|
||||
}
|
||||
|
||||
return nil, 0, 0
|
||||
}
|
||||
r := cgo.Handle(rh).Value().(*http.Request)
|
||||
|
||||
pinner := &runtime.Pinner{}
|
||||
@@ -613,6 +624,10 @@ func go_apache_request_headers(rh C.uintptr_t) (*C.go_string, C.size_t, C.uintpt
|
||||
|
||||
//export go_apache_request_cleanup
|
||||
func go_apache_request_cleanup(rh C.uintptr_t) {
|
||||
if rh == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
h := cgo.Handle(rh)
|
||||
p := h.Value().(*runtime.Pinner)
|
||||
p.Unpin()
|
||||
|
||||
2
testdata/request-headers.php
vendored
2
testdata/request-headers.php
vendored
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
apache_request_headers();
|
||||
|
||||
require_once __DIR__.'/_executor.php';
|
||||
|
||||
return function() {
|
||||
|
||||
Reference in New Issue
Block a user