mirror of
https://github.com/php/frankenphp.git
synced 2026-03-24 00:52:11 +01:00
This PR fixes a segmentation fault when using frankenphp.RegisterExtension with more than one extension. The issue was a type mismatch between Go and C: Go passes a slice of pointers, but the C code was treating it as a contiguous array of structs. This caused invalid memory access when iterating past the first element. I created a minimal reproduction repo here: [https://github.com/y-l-g/frankenphp-extensions-segfault-repro](https://www.google.com/url?sa=E&q=https%3A%2F%2Fgithub.com%2Fy-l-g%2Ffrankenphp-extensions-segfault-repro)
30 lines
541 B
Go
30 lines
541 B
Go
package frankenphp
|
|
|
|
//#include "frankenphp.h"
|
|
import "C"
|
|
import (
|
|
"sync"
|
|
"unsafe"
|
|
)
|
|
|
|
var (
|
|
extensions []*C.zend_module_entry
|
|
registerOnce sync.Once
|
|
)
|
|
|
|
// RegisterExtension registers a new PHP extension.
|
|
func RegisterExtension(me unsafe.Pointer) {
|
|
extensions = append(extensions, (*C.zend_module_entry)(me))
|
|
}
|
|
|
|
func registerExtensions() {
|
|
if len(extensions) == 0 {
|
|
return
|
|
}
|
|
|
|
registerOnce.Do(func() {
|
|
C.register_extensions((**C.zend_module_entry)(unsafe.Pointer(&extensions[0])), C.int(len(extensions)))
|
|
extensions = nil
|
|
})
|
|
}
|