From e6a9d1ca8d13c66c524ff0d34ef97f350da6d3a6 Mon Sep 17 00:00:00 2001 From: Pierre Joye Date: Sat, 23 Mar 2013 10:18:31 +0100 Subject: - fix x64 issues on windows with the various time types (overflow, signed and unsigned bits ops, etc.) causing crashes on start, error or log, must be done in win32/time.c for some of these functions too --- sapi/cli/php_cli_server.c | 59 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 16 deletions(-) (limited to 'sapi/cli/php_cli_server.c') diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c index ab7f4cfd19..e834e75957 100644 --- a/sapi/cli/php_cli_server.c +++ b/sapi/cli/php_cli_server.c @@ -24,11 +24,12 @@ #include #ifdef PHP_WIN32 -#include -#include -#include "win32/time.h" -#include "win32/signal.h" -#include "win32/php_registry.h" +# include +# include +# include "win32/time.h" +# include "win32/signal.h" +# include "win32/php_registry.h" +# include #else # include "php_config.h" #endif @@ -292,6 +293,34 @@ static const char php_cli_server_css[] = "\n"; /* }}} */ +#ifdef PHP_WIN32 +int php_cli_server_get_system_time(char *buf) { + struct _timeb system_time; + errno_t err; + + if (buf == NULL) { + return -1; + } + + _ftime(&system_time); + err = ctime_s(buf, 52, &(system_time.time) ); + if (err) { + return -1; + } + return 0; +} +#else +int php_cli_server_get_system_time(char *buf) { + struct timeval tv; + struct tm tm; + + gettimeofday(&tv, NULL); + php_localtime_r(&tv.tv_sec, &tm); + php_asctime_r(&tm, buf); + return 0; +} +#endif + static void char_ptr_dtor_p(char **p) /* {{{ */ { pefree(*p, 1); @@ -630,13 +659,11 @@ static void sapi_cli_server_register_variables(zval *track_vars_array TSRMLS_DC) static void sapi_cli_server_log_message(char *msg TSRMLS_DC) /* {{{ */ { - struct timeval tv; - struct tm tm; char buf[52]; - gettimeofday(&tv, NULL); - php_localtime_r(&tv.tv_sec, &tm); - php_asctime_r(&tm, buf); - { + + if (php_cli_server_get_system_time(buf) != 0) { + memmove(buf, "unknown time, can't be fetched", sizeof("unknown time, can't be fetched")); + } else { size_t l = strlen(buf); if (l > 0) { buf[l - 1] = '\0'; @@ -2394,12 +2421,12 @@ int do_cli_server(int argc, char **argv TSRMLS_DC) /* {{{ */ sapi_module.phpinfo_as_text = 0; { - struct timeval tv; - struct tm tm; char buf[52]; - gettimeofday(&tv, NULL); - php_localtime_r(&tv.tv_sec, &tm); - php_asctime_r(&tm, buf); + + if (php_cli_server_get_system_time(buf) != 0) { + memmove(buf, "unknown time, can't be fetched", sizeof("unknown time, can't be fetched")); + } + printf("PHP %s Development Server started at %s" "Listening on http://%s\n" "Document root is %s\n" -- cgit v1.2.1 From 2438490addfbfba51e12246a74588b2382caa08a Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Wed, 14 Aug 2013 14:42:36 +0200 Subject: slim post data --- sapi/cli/php_cli_server.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'sapi/cli/php_cli_server.c') diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c index a1bae67e74..5ec4143ad0 100644 --- a/sapi/cli/php_cli_server.c +++ b/sapi/cli/php_cli_server.c @@ -1726,8 +1726,7 @@ static void php_cli_server_client_populate_request_info(const php_cli_server_cli request_info->request_uri = client->request.request_uri; request_info->path_translated = client->request.path_translated; request_info->query_string = client->request.query_string; - request_info->post_data = client->request.content; - request_info->content_length = request_info->post_data_length = client->request.content_len; + request_info->content_length = client->request.content_len; request_info->auth_user = request_info->auth_password = request_info->auth_digest = NULL; if (SUCCESS == zend_hash_find(&client->request.headers, "Content-Type", sizeof("Content-Type"), (void**)&val)) { request_info->content_type = *val; -- cgit v1.2.1 From f33265d57281910652bb58f5f9d8bd9d9dd44fe8 Mon Sep 17 00:00:00 2001 From: Ard Biesheuvel Date: Mon, 9 Dec 2013 16:54:42 +0100 Subject: cli: don't cast away const in select() timeout argument The timeout argument to select() is modified to reflect the time remaining when the function returns on a non-timeout condition. Passing a pointer to const data and casting away the const-ness is asking for trouble, but for some reason, this trouble manifests itself only on non-x86 architectures [whose implementation of select() in glibc is different from the one supplied for x86] Fix this by passing a stack copy of the timeout argument to select() --- sapi/cli/php_cli_server.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'sapi/cli/php_cli_server.c') diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c index 105b8ae157..939eb5a501 100644 --- a/sapi/cli/php_cli_server.c +++ b/sapi/cli/php_cli_server.c @@ -893,9 +893,11 @@ static void php_cli_server_poller_remove(php_cli_server_poller *poller, int mode static int php_cli_server_poller_poll(php_cli_server_poller *poller, const struct timeval *tv) /* {{{ */ { + struct timeval t = *tv; + memmove(&poller->active.rfds, &poller->rfds, sizeof(poller->rfds)); memmove(&poller->active.wfds, &poller->wfds, sizeof(poller->wfds)); - return php_select(poller->max_fd + 1, &poller->active.rfds, &poller->active.wfds, NULL, (struct timeval *)tv); + return php_select(poller->max_fd + 1, &poller->active.rfds, &poller->active.wfds, NULL, &t); } /* }}} */ static int php_cli_server_poller_iter_on_active(php_cli_server_poller *poller, void *opaque, int(*callback)(void *, int fd, int events)) /* {{{ */ -- cgit v1.2.1