diff options
| author | Ryan Houdek <Sonicadvance1@gmail.com> | 2014-06-01 23:49:23 -0500 |
|---|---|---|
| committer | Ryan Houdek <Sonicadvance1@gmail.com> | 2014-06-01 23:55:38 -0500 |
| commit | 5d3382fb563ff15525fc4dc1f9ddbb8d84064835 (patch) | |
| tree | c45fdd44e5f5e800f103600de638e1ef60e23588 /Source/Core/Common/ArmCPUDetect.cpp | |
| parent | 31eedb2f79318002a4772087f96eb034f94787a1 (diff) | |
Fix a crash in ARM's CPUDetect on a malformed /proc/cpuinfo.
If a CPU string was incapable of being found we would return a null pointer, which would crash with strncpy.
Also if we couldn't get a CPU implementer we would call free() to a null pointer.
In addition, detect 64bit ARM running.
Diffstat (limited to 'Source/Core/Common/ArmCPUDetect.cpp')
| -rw-r--r-- | Source/Core/Common/ArmCPUDetect.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/Source/Core/Common/ArmCPUDetect.cpp b/Source/Core/Common/ArmCPUDetect.cpp index 80908b8992..15391c3fb7 100644 --- a/Source/Core/Common/ArmCPUDetect.cpp +++ b/Source/Core/Common/ArmCPUDetect.cpp @@ -11,7 +11,7 @@ #if !defined(BLACKBERRY) && !defined(IOS) && !defined(__SYMBIAN32__) const char procfile[] = "/proc/cpuinfo"; -char *GetCPUString() +std::string GetCPUString() { const char marker[] = "Hardware\t: "; char *cpu_string = nullptr; @@ -31,8 +31,10 @@ char *GetCPUString() cpu_string = strndup(cpu_string, strlen(cpu_string) - 1); // Strip the newline break; } - - return cpu_string; + if (cpu_string) + return std::string(cpu_string); + else + return ""; } unsigned char GetCPUImplementer() @@ -54,11 +56,10 @@ unsigned char GetCPUImplementer() implementer_string = buf + sizeof(marker) - 1; implementer_string = strndup(implementer_string, strlen(implementer_string) - 1); // Strip the newline sscanf(implementer_string, "0x%02hhx", &implementer); + free(implementer_string); break; } - free(implementer_string); - return implementer; } @@ -81,11 +82,10 @@ unsigned short GetCPUPart() part_string = buf + sizeof(marker) - 1; part_string = strndup(part_string, strlen(part_string) - 1); // Strip the newline sscanf(part_string, "0x%03hx", &part); + free(part_string); break; } - free(part_string); - return part; } @@ -156,9 +156,15 @@ void CPUInfo::Detect() // Set some defaults here // When ARMv8 cpus come out, these need to be updated. HTT = false; +#ifdef _M_ARM_64 + OS64bit = true; + CPU64bit = true; + Mode64bit = true; +#else OS64bit = false; CPU64bit = false; Mode64bit = false; +#endif vendor = VENDOR_ARM; // Get the information about the CPU @@ -209,7 +215,7 @@ void CPUInfo::Detect() bFP = false; bASIMD = false; #else - strncpy(cpu_string, GetCPUString(), sizeof(cpu_string)); + strncpy(cpu_string, GetCPUString().c_str(), sizeof(cpu_string)); bSwp = CheckCPUFeature("swp"); bHalf = CheckCPUFeature("half"); bThumb = CheckCPUFeature("thumb"); @@ -264,6 +270,7 @@ std::string CPUInfo::Summarize() if (bVFPv4) sum += ", VFPv4"; if (bIDIVa) sum += ", IDIVa"; if (bIDIVt) sum += ", IDIVt"; + if (CPU64bit) sum += ", 64-bit"; return sum; } |
