fix: SIGSEGV with env vars (#1278)

This commit is contained in:
Alliballibaba2
2024-12-21 02:38:01 +01:00
committed by GitHub
parent 0fc6ccc5ce
commit 92f95342d1
2 changed files with 8 additions and 7 deletions

View File

@@ -30,16 +30,18 @@ func initPHPThreads(numThreads int) error {
}
phpThreads = make([]*phpThread, numThreads)
if err := mainThread.start(); err != nil {
return err
}
// initialize all threads as inactive
// this needs to happen before starting the main thread
// since some extensions access environment variables on startup
for i := 0; i < numThreads; i++ {
phpThreads[i] = newPHPThread(i)
convertToInactiveThread(phpThreads[i])
}
if err := mainThread.start(); err != nil {
return err
}
// start the underlying C threads
ready := sync.WaitGroup{}
ready.Add(numThreads)

View File

@@ -73,11 +73,10 @@ func (thread *phpThread) getActiveRequest() *http.Request {
// Pin a string that is not null-terminated
// PHP's zend_string may contain null-bytes
func (thread *phpThread) pinString(s string) *C.char {
if s == "" {
sData := unsafe.StringData(s)
if sData == nil {
return nil
}
sData := unsafe.StringData(s)
thread.Pin(sData)
return (*C.char)(unsafe.Pointer(sData))