summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2019-03-31 17:28:50 +0200
committerAnatol Belski <ab@php.net>2019-03-31 17:33:36 +0200
commitdd0aca0c11f2572e37fd9583866f37d895a80e4e (patch)
tree839a1a0bd59259160598bf699fbec682a766090c
parente4a664ecf84fb74ecb8046deb77a1218f2f6cb62 (diff)
downloadphp-git-dd0aca0c11f2572e37fd9583866f37d895a80e4e.tar.gz
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/
-rw-r--r--main/main.c10
-rw-r--r--win32/winutil.c38
-rw-r--r--win32/winutil.h1
3 files changed, 48 insertions, 1 deletions
diff --git a/main/main.c b/main/main.c
index 6286990f62..de0d042843 100644
--- a/main/main.c
+++ b/main/main.c
@@ -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());
diff --git a/win32/winutil.c b/win32/winutil.c
index 18f890fb33..f0dc9d69e3 100644
--- a/win32/winutil.c
+++ b/win32/winutil.c
@@ -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;
+}/*}}}*/
+
diff --git a/win32/winutil.h b/win32/winutil.h
index 594f2d8d63..4b1d0448d5 100644
--- a/win32/winutil.h
+++ b/win32/winutil.h
@@ -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