Skip to content

Commit 2de4837

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Make extension compatibility check more liberal
2 parents 932842b + 886be26 commit 2de4837

File tree

1 file changed

+13
-32
lines changed

1 file changed

+13
-32
lines changed

win32/winutil.c

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ PHP_WINUTIL_API char *php_win32_get_username(void)
438438
return uname;
439439
}/*}}}*/
440440

441-
PHP_WINUTIL_API BOOL php_win32_image_compatible(const char *name, const char *path, char **err)
441+
static zend_always_inline BOOL is_compatible(const char *name, BOOL is_smaller, char *format, char **err)
442442
{/*{{{*/
443443
PLOADED_IMAGE img = ImageLoad(name, NULL);
444444

@@ -457,55 +457,36 @@ PHP_WINUTIL_API BOOL php_win32_image_compatible(const char *name, const char *pa
457457
/* VS 2015, 2017 and 2019 are binary compatible, but only forward compatible.
458458
It should be fine, if we load a module linked with an older one into
459459
the core linked with the newer one, but not the otherway round.
460+
Analogously, it should be fine, if a PHP build linked with an older version
461+
is used with a newer CRT, but not the other way round.
460462
Otherwise, if the linker major version is not same, it is an error, as
461463
per the current knowledge.
462464
463465
This check is to be extended as new VS versions come out. */
464-
if (14 == major && PHP_LINKER_MINOR < minor || PHP_LINKER_MAJOR != major)
466+
DWORD core_minor = (DWORD)(PHP_LINKER_MINOR/10);
467+
DWORD comp_minor = (DWORD)(minor/10);
468+
if (14 == major && (is_smaller ? core_minor < comp_minor : core_minor > comp_minor) || PHP_LINKER_MAJOR != major)
465469
#else
466470
if (PHP_LINKER_MAJOR != major)
467471
#endif
468472
{
469-
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);
473+
spprintf(err, 0, format, name, major, minor, PHP_LINKER_MAJOR, PHP_LINKER_MINOR);
470474
ImageUnload(img);
471475
return FALSE;
472476
}
473-
474477
ImageUnload(img);
475478

476479
return TRUE;
477480
}/*}}}*/
478481

482+
PHP_WINUTIL_API BOOL php_win32_image_compatible(const char *name, char **err)
483+
{/*{{{*/
484+
return is_compatible(name, TRUE, "Can't load module '%s' as it's linked with %u.%u, but the core is linked with %d.%d", err);
485+
}/*}}}*/
486+
479487
/* Expect a CRT name DLL. */
480488
PHP_WINUTIL_API BOOL php_win32_crt_compatible(const char *name, char **err)
481489
{/*{{{*/
482-
PLOADED_IMAGE img = ImageLoad(name, NULL);
483-
484-
if (!img) {
485-
DWORD _err = GetLastError();
486-
char *err_txt = php_win32_error_to_msg(_err);
487-
spprintf(err, 0, "Failed to load %s, %s", name, err_txt);
488-
free(err_txt);
489-
return FALSE;
490-
}
491-
492-
DWORD major = img->FileHeader->OptionalHeader.MajorLinkerVersion;
493-
DWORD minor = img->FileHeader->OptionalHeader.MinorLinkerVersion;
494-
495-
#if PHP_LINKER_MAJOR == 14
496-
DWORD core_minor = (DWORD)(PHP_LINKER_MINOR/10);
497-
DWORD comp_minor = (DWORD)(minor/10);
498-
if (14 == major && core_minor > comp_minor || PHP_LINKER_MAJOR != major)
499-
#else
500-
if (PHP_LINKER_MAJOR != major)
501-
#endif
502-
{
503-
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);
504-
ImageUnload(img);
505-
return FALSE;
506-
}
507-
ImageUnload(img);
508-
509-
return TRUE;
490+
return is_compatible(name, FALSE, "'%s' %u.%u is not compatible with this PHP build linked with %d.%d", err);
510491
}/*}}}*/
511492

0 commit comments

Comments
 (0)