diff options
Diffstat (limited to 'chromium/base/system')
-rw-r--r-- | chromium/base/system/sys_info.h | 4 | ||||
-rw-r--r-- | chromium/base/system/sys_info_chromeos.cc | 17 | ||||
-rw-r--r-- | chromium/base/system/sys_info_linux.cc | 1 | ||||
-rw-r--r-- | chromium/base/system/sys_info_unittest.cc | 29 |
4 files changed, 51 insertions, 0 deletions
diff --git a/chromium/base/system/sys_info.h b/chromium/base/system/sys_info.h index 057b0dc45e8..ae3fef01811 100644 --- a/chromium/base/system/sys_info.h +++ b/chromium/base/system/sys_info.h @@ -160,6 +160,10 @@ class BASE_EXPORT SysInfo { // Returns the kernel version of the host operating system. static std::string KernelVersion(); + + // Crashes if running on Chrome OS non-test image. Use only for really + // sensitive and risky use cases. + static void CrashIfChromeOSNonTestImage(); #endif // defined(OS_CHROMEOS) #if defined(OS_ANDROID) diff --git a/chromium/base/system/sys_info_chromeos.cc b/chromium/base/system/sys_info_chromeos.cc index 1d688f13491..6be670fb0d3 100644 --- a/chromium/base/system/sys_info_chromeos.cc +++ b/chromium/base/system/sys_info_chromeos.cc @@ -223,4 +223,21 @@ void SysInfo::SetChromeOSVersionInfoForTest(const std::string& lsb_release, g_chrome_os_version_info.Get().Parse(); } +// static +void SysInfo::CrashIfChromeOSNonTestImage() { + if (!IsRunningOnChromeOS()) + return; + + // On the test images etc/lsb-release has a line: + // CHROMEOS_RELEASE_TRACK=testimage-channel. + const char kChromeOSReleaseTrack[] = "CHROMEOS_RELEASE_TRACK"; + const char kTestImageRelease[] = "testimage-channel"; + + std::string track; + CHECK(SysInfo::GetLsbReleaseValue(kChromeOSReleaseTrack, &track)); + + // Crash if can't find test-image marker in the release track. + CHECK_NE(track.find(kTestImageRelease), std::string::npos); +} + } // namespace base diff --git a/chromium/base/system/sys_info_linux.cc b/chromium/base/system/sys_info_linux.cc index d9bfa496fde..f69569fb51c 100644 --- a/chromium/base/system/sys_info_linux.cc +++ b/chromium/base/system/sys_info_linux.cc @@ -8,6 +8,7 @@ #include <stdint.h> #include <limits> +#include <sstream> #include "base/check.h" #include "base/files/file_util.h" diff --git a/chromium/base/system/sys_info_unittest.cc b/chromium/base/system/sys_info_unittest.cc index 68add20e022..6c9c226a92e 100644 --- a/chromium/base/system/sys_info_unittest.cc +++ b/chromium/base/system/sys_info_unittest.cc @@ -21,6 +21,7 @@ #include "base/threading/platform_thread.h" #include "base/time/time.h" #include "build/build_config.h" +#include "testing/gtest/include/gtest/gtest-death-test.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" @@ -268,6 +269,34 @@ TEST_F(SysInfoTest, IsRunningOnChromeOS) { EXPECT_TRUE(SysInfo::IsRunningOnChromeOS()); } +TEST_F(SysInfoTest, CrashOnBaseImage) { + const char kLsbRelease2[] = + "CHROMEOS_RELEASE_NAME=Chrome OS\n" + "CHROMEOS_RELEASE_VERSION=1.2.3.4\n" + "CHROMEOS_RELEASE_TRACK=stable-channel\n"; + SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease2, Time()); + EXPECT_TRUE(SysInfo::IsRunningOnChromeOS()); + EXPECT_DEATH_IF_SUPPORTED({ SysInfo::CrashIfChromeOSNonTestImage(); }, ""); +} + +TEST_F(SysInfoTest, NoCrashOnTestImage) { + const char kLsbRelease2[] = + "CHROMEOS_RELEASE_NAME=Chrome OS\n" + "CHROMEOS_RELEASE_VERSION=1.2.3.4\n" + "CHROMEOS_RELEASE_TRACK=testimage-channel\n"; + SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease2, Time()); + EXPECT_TRUE(SysInfo::IsRunningOnChromeOS()); + // Should not crash. + SysInfo::CrashIfChromeOSNonTestImage(); +} + +TEST_F(SysInfoTest, NoCrashOnLinuxBuild) { + SysInfo::SetChromeOSVersionInfoForTest("", Time()); + EXPECT_FALSE(SysInfo::IsRunningOnChromeOS()); + // Should not crash. + SysInfo::CrashIfChromeOSNonTestImage(); +} + #endif // OS_CHROMEOS } // namespace base |