fixup! [M120 Migration] Notify media device state to webbrowser
[platform/framework/web/chromium-efl.git] / base / stack_canary_linux_unittest.cc
1 // Copyright 2021 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/stack_canary_linux.h"
6
7 #include "build/build_config.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace base {
11
12 #if defined(LIBC_GLIBC) && \
13     (defined(ARCH_CPU_ARM_FAMILY) || defined(ARCH_CPU_X86_FAMILY))
14
15 namespace {
16 __attribute__((noinline, optnone)) void ResetCanaryAndReturn() {
17   // Create a buffer >=8 bytes to force the stack protector on this function,
18   // which should work as long as -fno-stack-protector isn't passed in the
19   // default options. We compile this file with -fstack-protector-all, but it
20   // may be overridden with -fstack-protector or -fstack-protector-strong.
21   [[maybe_unused]] char buffer[10];
22   ResetStackCanaryIfPossible();
23 }
24 }  // namespace
25
26 // Essentially tests that ResetStackCanaryIfPossible() changes the
27 // actual reference canary that is checked in the function prologue.
28 TEST(StackCanary, ChangingStackCanaryCrashesOnReturn) {
29   ASSERT_DEATH(ResetCanaryAndReturn(), "stack smashing");
30 }
31
32 #if !defined(NDEBUG)
33 // Tests that the useful debug message works--specifically that on death, it
34 // prints out the bug URL with useful information.
35 TEST(StackCanary, ChangingStackCanaryPrintsDebugMessage) {
36   SetStackSmashingEmitsDebugMessage();
37   ASSERT_DEATH(ResetCanaryAndReturn(), "crbug\\.com/1206626");
38 }
39 #endif  // !defined(NDEBUG)
40
41 #endif  // defined(LIBC_GLIBC) && (defined(ARCH_CPU_ARM_FAMILY) ||
42         // defined(ARCH_CPU_X86_FAMILY))
43
44 }  // namespace base