dart-sdk/runtime/vm/cpuid.h
Vyacheslav Egorov c55f2924fe [vm] Guard against bad brand strings in CPUID
Brand string is supposed to be NULL-terminated.

However we are seeing cases in the wild where
this string is not null-terminated which
causes buffer overrun when trying to print it.

Add trailing '\0' to the brand string to guard
against such cases.

Fixes https://github.com/flutter/flutter/issues/114346

TEST=manually

Change-Id: I21e545bd2fb52336a1fcd7edacb0b867740e8d61
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/269720
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2022-11-14 15:42:52 +00:00

51 lines
1.3 KiB
C++

// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#ifndef RUNTIME_VM_CPUID_H_
#define RUNTIME_VM_CPUID_H_
#include "vm/globals.h"
#if !defined(DART_HOST_OS_MACOS)
#include "vm/allocation.h"
#include "vm/cpuinfo.h"
namespace dart {
class CpuId : public AllStatic {
public:
#if defined(HOST_ARCH_IA32) || defined(HOST_ARCH_X64)
static void Init();
static void Cleanup();
// Caller must free the result of field.
static const char* field(CpuInfoIndices idx);
#else
static void Init() {}
static void Cleanup() {}
static const char* field(CpuInfoIndices idx) { return nullptr; }
#endif
private:
// Caller must free the result of id_string and brand_string.
static const char* id_string();
static const char* brand_string();
static bool sse2() { return sse2_; }
static bool sse41() { return sse41_; }
static bool popcnt() { return popcnt_; }
static bool abm() { return abm_; }
static bool sse2_;
static bool sse41_;
static bool popcnt_;
static bool abm_;
static const char* id_string_;
static const char* brand_string_;
};
} // namespace dart
#endif // !defined(DART_HOST_OS_MACOS)
#endif // RUNTIME_VM_CPUID_H_