Skip to content

Commit 45823c5

Browse files
fix: catches panic on invalid status code (#1920)
1 parent f8ea48c commit 45823c5

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

frankenphp.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,18 @@ func go_write_headers(threadIndex C.uintptr_t, status C.int, headers *C.zend_lli
475475
current = current.next
476476
}
477477

478-
fc.responseWriter.WriteHeader(int(status))
478+
goStatus := int(status)
479479

480-
if status >= 100 && status < 200 {
480+
// go panics on invalid status code
481+
// https://github.com/golang/go/blob/9b8742f2e79438b9442afa4c0a0139d3937ea33f/src/net/http/server.go#L1162
482+
if goStatus < 100 || goStatus > 999 {
483+
logger.Warn(fmt.Sprintf("Invalid response status code %v", goStatus))
484+
goStatus = 500
485+
}
486+
487+
fc.responseWriter.WriteHeader(goStatus)
488+
489+
if goStatus >= 100 && goStatus < 200 {
481490
// Clear headers, it's not automatically done by ResponseWriter.WriteHeader() for 1xx responses
482491
h := fc.responseWriter.Header()
483492
for k := range h {

0 commit comments

Comments
 (0)