1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Implement stricter CRT check

This aligns with the recommendations about VS2015, VS2017 and VS2019
compatibility.

More info below
https://devblogs.microsoft.com/cppblog/cpp-binary-compatibility-and-pain-free-upgrades-to-visual-studio-2019/
This commit is contained in:
Anatol Belski
2019-03-31 17:28:50 +02:00
parent e4a664ecf8
commit dd0aca0c11
3 changed files with 48 additions and 1 deletions

View File

@@ -2187,6 +2187,16 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
#endif
#ifdef PHP_WIN32
# if PHP_LINKER_MAJOR == 14
/* Extend for other CRT if needed. */
char *img_err;
if (!php_win32_crt_compatible("vcruntime140.dll", &img_err)) {
php_error(E_CORE_WARNING, img_err);
efree(img_err);
return FAILURE;
}
# endif
/* start up winsock services */
if (WSAStartup(wVersionRequested, &wsaData) != 0) {
php_printf("\nwinsock.dll unusable. %d\n", WSAGetLastError());

View File

@@ -460,7 +460,7 @@ PHP_WINUTIL_API BOOL php_win32_image_compatible(const char *name, const char *pa
per the current knowledge.
This check is to be extended as new VS versions come out. */
if (14 == major && PHP_LINKER_MINOR < minor
if (14 == PHP_LINKER_MAJOR && 14 == major && PHP_LINKER_MINOR < minor
|| PHP_LINKER_MAJOR != major) {
spprintf(err, 0, "Can't load module '%s' as it's linked with %u.%u, but the core is linked with %d.%d", name, major, minor, PHP_LINKER_MAJOR, PHP_LINKER_MINOR);
ImageUnload(img);
@@ -472,3 +472,39 @@ PHP_WINUTIL_API BOOL php_win32_image_compatible(const char *name, const char *pa
return TRUE;
}/*}}}*/
/* Expect a CRT name DLL. */
PHP_WINUTIL_API BOOL php_win32_crt_compatible(const char *name, char **err)
{/*{{{*/
PLOADED_IMAGE img = ImageLoad(name, NULL);
if (!img) {
DWORD _err = GetLastError();
char *err_txt = php_win32_error_to_msg(_err);
spprintf(err, 0, "Failed to load %s, %s", name, err_txt);
free(err_txt);
return FALSE;
}
DWORD major = img->FileHeader->OptionalHeader.MajorLinkerVersion;
DWORD minor = img->FileHeader->OptionalHeader.MinorLinkerVersion;
#if PHP_LINKER_MAJOR == 14
DWORD core_minor = (DWORD)(PHP_LINKER_MINOR/10);
DWORD comp_minor = (DWORD)(minor/10);
if (core_minor > comp_minor) {
spprintf(err, 0, "'%s' %u.%u is not compatible with this PHP build linked with %d.%d", name, major, minor, PHP_LINKER_MAJOR, PHP_LINKER_MINOR);
ImageUnload(img);
return FALSE;
}
#else
if (PHP_LINKER_MAJOR != major) {
spprintf(err, 0, "'%s' %u.%u is not compatible with this PHP build linked with %d.%d", name, major, minor, PHP_LINKER_MAJOR, PHP_LINKER_MINOR);
ImageUnload(img);
return FALSE;
}
#endif
ImageUnload(img);
return TRUE;
}/*}}}*/

View File

@@ -56,5 +56,6 @@ PHP_WINUTIL_API int php_win32_code_to_errno(unsigned long w32Err);
PHP_WINUTIL_API char *php_win32_get_username(void);
PHP_WINUTIL_API BOOL php_win32_image_compatible(const char *img, const char *path, char **err);
PHP_WINUTIL_API BOOL php_win32_crt_compatible(const char *img, char **err);
#endif