mirror of
https://github.com/php/php-src.git
synced 2024-09-22 18:37:25 +00:00
Prevent crash in case of wrong arguments to CRT functions (strftime()) on PHP complead by MS VC2005
This commit is contained in:
parent
bab1ce1429
commit
c2e04e8364
43
main/main.c
43
main/main.c
@ -1424,6 +1424,36 @@ int php_register_extensions(zend_module_entry **ptr, int count TSRMLS_DC)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
#if defined(PHP_WIN32) && defined(_MSC_VER) && (_MSC_VER >= 1400)
|
||||
static _invalid_parameter_handler old_invalid_parameter_handler;
|
||||
|
||||
void dummy_invalid_parameter_handler(
|
||||
const wchar_t *expression,
|
||||
const wchar_t *function,
|
||||
const wchar_t *file,
|
||||
unsigned int line,
|
||||
uintptr_t pEwserved)
|
||||
{
|
||||
static int called = 0;
|
||||
char buf[1024];
|
||||
int len;
|
||||
|
||||
if (!called) {
|
||||
called = 1;
|
||||
if (function) {
|
||||
if (file) {
|
||||
len = _snprintf(buf, sizeof(buf)-1, "Invalid parameter detected in CRT function '%ws' (%ws:%d)", function, file, line);
|
||||
} else {
|
||||
len = _snprintf(buf, sizeof(buf)-1, "Invalid parameter detected in CRT function '%ws'", function);
|
||||
}
|
||||
} else {
|
||||
len = _snprintf(buf, sizeof(buf)-1, "Invalid CRT parameters detected");
|
||||
}
|
||||
zend_error(E_WARNING, "%s", buf);
|
||||
called = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* {{{ php_module_startup
|
||||
*/
|
||||
@ -1454,6 +1484,13 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
|
||||
php_os="WIN32";
|
||||
}
|
||||
}
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
|
||||
old_invalid_parameter_handler =
|
||||
_set_invalid_parameter_handler(dummy_invalid_parameter_handler);
|
||||
if (old_invalid_parameter_handler != NULL) {
|
||||
_set_invalid_parameter_handler(old_invalid_parameter_handler);
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
php_os=PHP_OS;
|
||||
#endif
|
||||
@ -1707,6 +1744,12 @@ void php_module_shutdown(TSRMLS_D)
|
||||
php_shutdown_temporary_directory();
|
||||
|
||||
module_initialized = 0;
|
||||
|
||||
#if defined(PHP_WIN32) && defined(_MSC_VER) && (_MSC_VER >= 1400)
|
||||
if (old_invalid_parameter_handler == NULL) {
|
||||
_set_invalid_parameter_handler(old_invalid_parameter_handler);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user