X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=src%2Fphp_http_env.c;fp=src%2Fphp_http_env.c;h=fdbdd92ee97ae08e9d7df7966737d43dc92a2f97;hp=9c88822e3db948ec3331e4d706084f22db7be391;hb=e3976774f27b4129cbfd7d227aaa7e177f1b735c;hpb=29bdc7039ca5ffe71c465d957da9922881b6859d diff --git a/src/php_http_env.c b/src/php_http_env.c index 9c88822..fdbdd92 100644 --- a/src/php_http_env.c +++ b/src/php_http_env.c @@ -417,12 +417,10 @@ ZEND_RESULT_CODE php_http_env_set_response_status_line(long code, php_http_versi { sapi_header_line h = {NULL, 0, 0}; ZEND_RESULT_CODE ret; - char *line; - h.line_len = spprintf(&line, 0, "HTTP/%u.%u %ld %s", v->major, v->minor, code, php_http_env_get_response_status_for_code(code)); - h.line = line; + h.line_len = spprintf(&h.line, 0, "HTTP/%u.%u %ld %s", v->major, v->minor, code, php_http_env_get_response_status_for_code(code)); ret = sapi_header_op(SAPI_HEADER_REPLACE, (void *) &h); - efree(line); + efree(h.line); return ret; } @@ -434,9 +432,10 @@ ZEND_RESULT_CODE php_http_env_set_response_protocol_version(php_http_version_t * ZEND_RESULT_CODE php_http_env_set_response_header(long http_code, const char *header_str, size_t header_len, zend_bool replace) { - sapi_header_line h = {header_str, header_len, http_code}; + sapi_header_line h = {estrndup(header_str, header_len), header_len, http_code}; ZEND_RESULT_CODE ret = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, (void *) &h); + efree(h.line); return ret; } @@ -444,16 +443,14 @@ ZEND_RESULT_CODE php_http_env_set_response_header_va(long http_code, zend_bool r { ZEND_RESULT_CODE ret = FAILURE; sapi_header_line h = {NULL, 0, http_code}; - char *line; - h.line_len = vspprintf(&line, 0, fmt, argv); - h.line = line; + h.line_len = vspprintf(&h.line, 0, fmt, argv); if (h.line) { if (h.line_len) { ret = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, (void *) &h); } - efree(line); + efree(h.line); } return ret; } @@ -502,19 +499,17 @@ ZEND_RESULT_CODE php_http_env_set_response_header_value(long http_code, const ch } else { sapi_header_line h; ZEND_RESULT_CODE ret; - char *line; if (name_len > INT_MAX) { return FAILURE; } h.response_code = http_code; - h.line_len = spprintf(&line, 0, "%s: %s", name_str, data->val); - h.line = line; + h.line_len = spprintf(&h.line, 0, "%s: %s", name_str, data->val); ret = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, (void *) &h); zend_string_release(data); - PTR_FREE(line); + PTR_FREE(h.line); return ret; }