]> granicus.if.org Git - php/commitdiff
Possible fix for bug #77357
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 3 Jan 2019 09:24:48 +0000 (10:24 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Thu, 3 Jan 2019 09:24:48 +0000 (10:24 +0100)
Don't invoke CPUID with feature levels above the supported maximum.
In this case CPUID will return the highest supported basic information
leaf, which will have unrelated bits in the relevant positions.

Zend/zend_cpuinfo.c

index ea1f08f948c82833764b06975177d7b9a7620419..4cbd2ac776751f8b7fb0860b6efb7c0e6aae2138 100644 (file)
@@ -77,16 +77,24 @@ void zend_cpu_startup(void)
 {
        if (!cpuinfo.initialized) {
                zend_cpu_info ebx;
+               int max_feature;
 
                cpuinfo.initialized = 1;
                __zend_cpuid(0, 0, &cpuinfo);
-               if (cpuinfo.eax == 0) {
+               max_feature = cpuinfo.eax;
+               if (max_feature == 0) {
                        return;
                }
+
                __zend_cpuid(1, 0, &cpuinfo);
+
                /* for avx2 */
-               __zend_cpuid(7, 0, &ebx);
-               cpuinfo.ebx = ebx.ebx;
+               if (max_feature >= 7) {
+                       __zend_cpuid(7, 0, &ebx);
+                       cpuinfo.ebx = ebx.ebx;
+               } else {
+                       cpuinfo.ebx = 0;
+               }
        }
 }