]> granicus.if.org Git - php/commitdiff
Implement stricter CRT check
authorAnatol Belski <ab@php.net>
Sun, 31 Mar 2019 15:28:50 +0000 (17:28 +0200)
committerAnatol Belski <ab@php.net>
Sun, 31 Mar 2019 15:33:36 +0000 (17:33 +0200)
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/

main/main.c
win32/winutil.c
win32/winutil.h

index 6286990f62f8994ce7e07f9b48fdd45656877a97..de0d0428435f7d336cd96a04516573bf07cc8880 100644 (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());
index 18f890fb33e09cf403f39e41503ce097f4da4b21..f0dc9d69e3e04db6a2b3faf3c8f50679d415e411 100644 (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;
+}/*}}}*/
+
index 594f2d8d6382a8101051d5ec48fd4de835bf62d3..4b1d0448d51d761e82f765f8f8c2e7685961875c 100644 (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