php-src icon indicating copy to clipboard operation
php-src copied to clipboard

sapi_send_headers bug

Open alexlongguo opened this issue 4 years ago • 3 comments

Description

version:php 7.4.27 file: SAPI.c function: sapi_send_headers code:

	if (sapi_module.send_headers) {
		retval = sapi_module.send_headers(&SG(sapi_headers));
	} else {
		retval = SAPI_HEADER_DO_SEND;
	}

	switch (retval) {
		case SAPI_HEADER_DO_SEND: {
				......
				sapi_module.send_header(&http_status_line, SG(server_context));
			}

describe: I didn't set sapi_module.send_headers in sapi_module_struct, so this function is NULL. retval = SAPI_HEADER_DO_SEND; But call sapi_module.send_header in this switch,it could cause crash.

PHP Version

php 7.4.27

Operating System

No response

alexlongguo avatar Mar 02 '22 08:03 alexlongguo

The switch uses send_header, not send_headers. No 's'.

damianwadley avatar Mar 02 '22 08:03 damianwadley

The switch uses send_header, not send_headers. No 's'.

I set sapi_module.send_headers = NULL, sapi_module.send_header=NULL

Maybe need:

if (sapi_module.send_header){
sapi_module.send_header(&http_status_line, SG(server_context));
}

alexlongguo avatar Mar 02 '22 08:03 alexlongguo

Well, to my knowledge there is no comprehensive documentation about the sapi_module_struct, but from looking at the implementation of the embed SAPI, send_header is supposed to be not NULL; instead, a function which does nothing is used: https://github.com/php/php-src/blob/0e88f749ff00d70f0d0cd2caa1ebb17e0103cd8c/sapi/embed/php_embed.c#L100-L102 So this doesn't look like a bug to me.

cmb69 avatar Mar 02 '22 10:03 cmb69