efree(err1);
}
+#ifdef PHP_WIN32
+ if (!php_win32_image_compatible(libpath, NULL, &err1)) {
+ php_error_docref(NULL, error_type, err1);
+ efree(err1);
+ efree(libpath);
+ DL_UNLOAD(handle);
+ return FAILURE;
+ }
+#endif
+
efree(libpath);
get_module = (zend_module_entry *(*)(void)) DL_FETCH_SYMBOL(handle, "get_module");
#endif
if (IS_ABSOLUTE_PATH(filename, length)) {
+#ifdef PHP_WIN32
+ char *err;
+ if (!php_win32_image_compatible(filename, NULL, &err)) {
+ php_error(E_CORE_WARNING, err);
+ return FAILURE;
+ }
+#endif
zend_load_extension(filename);
} else {
DL_HANDLE handle;
efree(err1);
}
+#ifdef PHP_WIN32
+ if (!php_win32_image_compatible(libpath, NULL, &err1)) {
+ php_error(E_CORE_WARNING, err1);
+ efree(err1);
+ efree(libpath);
+ DL_UNLOAD(handle);
+ return FAILURE;
+ }
+#endif
+
zend_load_extension_handle(handle, libpath);
efree(libpath);
}
#include "codepage.h"
#include <bcrypt.h>
#include <lmcons.h>
+#include <imagehlp.h>
+
PHP_WINUTIL_API char *php_win32_error_to_msg(HRESULT error)
{/*{{{*/
return uname;
}/*}}}*/
+
+PHP_WINUTIL_API BOOL php_win32_image_compatible(const char *name, const char *path, 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;
+
+ /* VS 2015, 2017 and 2019 are binary compatible, but only forward compatible.
+ It should be fine, if we load a module linked with an older one into
+ the core linked with the newer one, but not the otherway round.
+ Otherwise, if the linker major version is not same, it is an error, as
+ per the current knowledge.
+
+ This check is to be extended as new VS versions come out. */
+ if (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);
+ return FALSE;
+ }
+
+ ImageUnload(img);
+
+ return TRUE;
+}/*}}}*/
+