diff options
Diffstat (limited to 'sapi/cli/php_cli_server.c')
-rw-r--r-- | sapi/cli/php_cli_server.c | 59 |
1 files changed, 17 insertions, 42 deletions
diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c index e918a686a1..1097b4769c 100644 --- a/sapi/cli/php_cli_server.c +++ b/sapi/cli/php_cli_server.c @@ -214,6 +214,8 @@ static php_cli_server_http_response_status_code_pair template_map[] = { static int php_cli_output_is_tty = OUTPUT_NOT_CHECKED; #endif +static const char php_cli_server_request_error_unexpected_eof[] = "Unexpected EOF"; + static size_t php_cli_server_client_send_through(php_cli_server_client *client, const char *str, size_t str_len); static php_cli_server_chunk *php_cli_server_chunk_heap_new_self_contained(size_t len); static void php_cli_server_buffer_append(php_cli_server_buffer *buffer, php_cli_server_chunk *chunk); @@ -413,7 +415,7 @@ static void add_response_header(sapi_header_struct *h, zval *return_value) /* {{ do { p++; } while (*p == ' ' || *p == '\t'); - add_assoc_stringl_ex(return_value, s, (uint)len, p, h->header_len - (p - h->header)); + add_assoc_stringl_ex(return_value, s, (uint32_t)len, p, h->header_len - (p - h->header)); free_alloca(s, use_heap); } } @@ -607,7 +609,7 @@ static int sapi_cli_server_register_entry_cb(char **entry, int num_args, va_list zval *track_vars_array = va_arg(args, zval *); if (hash_key->key) { char *real_key, *key; - uint i; + uint32_t i; key = estrndup(ZSTR_VAL(hash_key->key), ZSTR_LEN(hash_key->key)); for(i=0; i<ZSTR_LEN(hash_key->key); i++) { if (key[i] == '-') { @@ -931,9 +933,6 @@ static size_t php_cli_server_buffer_size(const php_cli_server_buffer *buffer) /* static php_cli_server_chunk *php_cli_server_chunk_immortal_new(const char *buf, size_t len) /* {{{ */ { php_cli_server_chunk *chunk = pemalloc(sizeof(php_cli_server_chunk), 1); - if (!chunk) { - return NULL; - } chunk->type = PHP_CLI_SERVER_CHUNK_IMMORTAL; chunk->next = NULL; @@ -945,9 +944,6 @@ static php_cli_server_chunk *php_cli_server_chunk_immortal_new(const char *buf, static php_cli_server_chunk *php_cli_server_chunk_heap_new(void *block, char *buf, size_t len) /* {{{ */ { php_cli_server_chunk *chunk = pemalloc(sizeof(php_cli_server_chunk), 1); - if (!chunk) { - return NULL; - } chunk->type = PHP_CLI_SERVER_CHUNK_HEAP; chunk->next = NULL; @@ -960,9 +956,6 @@ static php_cli_server_chunk *php_cli_server_chunk_heap_new(void *block, char *bu static php_cli_server_chunk *php_cli_server_chunk_heap_new_self_contained(size_t len) /* {{{ */ { php_cli_server_chunk *chunk = pemalloc(sizeof(php_cli_server_chunk) + len, 1); - if (!chunk) { - return NULL; - } chunk->type = PHP_CLI_SERVER_CHUNK_HEAP; chunk->next = NULL; @@ -1218,12 +1211,6 @@ static php_socket_t php_network_listen_socket(const char *host, int *port, int s #if HAVE_GETADDRINFO && HAVE_IPV6 case AF_INET6: sa = pemalloc(sizeof(struct sockaddr_in6), 1); - if (!sa) { - closesocket(retval); - retval = SOCK_ERR; - *errstr = NULL; - goto out; - } *(struct sockaddr_in6 *)sa = *(struct sockaddr_in6 *)*p; ((struct sockaddr_in6 *)sa)->sin6_port = htons(*port); *socklen = sizeof(struct sockaddr_in6); @@ -1231,12 +1218,6 @@ static php_socket_t php_network_listen_socket(const char *host, int *port, int s #endif case AF_INET: sa = pemalloc(sizeof(struct sockaddr_in), 1); - if (!sa) { - closesocket(retval); - retval = SOCK_ERR; - *errstr = NULL; - goto out; - } *(struct sockaddr_in *)sa = *(struct sockaddr_in *)*p; ((struct sockaddr_in *)sa)->sin_port = htons(*port); *socklen = sizeof(struct sockaddr_in); @@ -1373,10 +1354,6 @@ static void php_cli_server_request_translate_vpath(php_cli_server_request *reque size_t prev_path_len = 0; int is_static_file = 0; - if (!buf) { - return; - } - memmove(p, document_root, document_root_len); p += document_root_len; vpath = p; @@ -1461,7 +1438,7 @@ static void php_cli_server_request_translate_vpath(php_cli_server_request *reque } #ifdef PHP_WIN32 { - uint i = 0; + uint32_t i = 0; for (;i<request->vpath_len;i++) { if (request->vpath[i] == '\\') { request->vpath[i] = '/'; @@ -1698,9 +1675,6 @@ static int php_cli_server_client_read_request_on_body(php_http_parser *parser, c php_cli_server_client *client = parser->data; if (!client->request.content) { client->request.content = pemalloc(parser->content_length, 1); - if (!client->request.content) { - return -1; - } client->request.content_len = 0; } client->request.content = perealloc(client->request.content, client->request.content_len + length, 1); @@ -1761,7 +1735,7 @@ static int php_cli_server_client_read_request(php_cli_server_client *client, cha *errstr = php_socket_strerror(err, NULL, 0); return -1; } else if (nbytes_read == 0) { - *errstr = estrdup("Unexpected EOF"); + *errstr = estrdup(php_cli_server_request_error_unexpected_eof); return -1; } client->parser.data = client; @@ -1776,9 +1750,6 @@ static int php_cli_server_client_read_request(php_cli_server_client *client, cha } if (client->current_header_name) { char *header_name = safe_pemalloc(client->current_header_name_len, 1, 1, 1); - if (!header_name) { - return -1; - } memmove(header_name, client->current_header_name, client->current_header_name_len); client->current_header_name = header_name; client->current_header_name_allocated = 1; @@ -1898,7 +1869,7 @@ static void php_cli_server_client_dtor(php_cli_server_client *client) /* {{{ */ static void php_cli_server_close_connection(php_cli_server *server, php_cli_server_client *client) /* {{{ */ { -#ifdef DEBUG +#if PHP_DEBUG php_cli_server_logf("%s Closing", client->addr_str); #endif zend_hash_index_del(&server->clients, client->sock); @@ -2387,7 +2358,13 @@ static int php_cli_server_recv_event_read_request(php_cli_server *server, php_cl char *errstr = NULL; int status = php_cli_server_client_read_request(client, &errstr); if (status < 0) { - php_cli_server_logf("%s Invalid request (%s)", client->addr_str, errstr); + if (strcmp(errstr, php_cli_server_request_error_unexpected_eof) == 0 && client->parser.state == s_start_req) { +#if PHP_DEBUG + php_cli_server_logf("%s Closed without sending a request; it was probably just an unused speculative preconnection", client->addr_str); +#endif + } else { + php_cli_server_logf("%s Invalid request (%s)", client->addr_str, errstr); + } efree(errstr); php_cli_server_close_connection(server, client); return FAILURE; @@ -2448,9 +2425,6 @@ static int php_cli_server_do_event_for_each_fd_callback(void *_params, php_socke php_socket_t client_sock; socklen_t socklen = server->socklen; struct sockaddr *sa = pemalloc(server->socklen, 1); - if (!sa) { - return FAILURE; - } client_sock = accept(server->server_sock, sa, &socklen); if (!ZEND_VALID_SOCKET(client_sock)) { char *errstr; @@ -2465,13 +2439,14 @@ static int php_cli_server_do_event_for_each_fd_callback(void *_params, php_socke closesocket(client_sock); return SUCCESS; } - if (!(client = pemalloc(sizeof(php_cli_server_client), 1)) || FAILURE == php_cli_server_client_ctor(client, server, client_sock, sa, socklen)) { + client = pemalloc(sizeof(php_cli_server_client), 1); + if (FAILURE == php_cli_server_client_ctor(client, server, client_sock, sa, socklen)) { php_cli_server_logf("Failed to create a new request object"); pefree(sa, 1); closesocket(client_sock); return SUCCESS; } -#ifdef DEBUG +#if PHP_DEBUG php_cli_server_logf("%s Accepted", client->addr_str); #endif zend_hash_index_update_ptr(&server->clients, client_sock, client); |