15f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// Test the blacklist functionality of ASan
25f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany
35f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// RUN: echo "fun:*brokenFunction*" > %tmp
45f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// RUN: echo "global:*badGlobal*" >> %tmp
55f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// RUN: echo "src:*blacklist-extra.cc" >> %tmp
66efa4d6cf9bb214a5e8ddbb224a69b38c4ae6de6Alexey Samsonov// RUN: %clangxx_asan -fsanitize-blacklist=%tmp -O0 %s -o %t \
72d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// RUN: %p/Helpers/blacklist-extra.cc && %run %t 2>&1
86efa4d6cf9bb214a5e8ddbb224a69b38c4ae6de6Alexey Samsonov// RUN: %clangxx_asan -fsanitize-blacklist=%tmp -O1 %s -o %t \
92d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// RUN: %p/Helpers/blacklist-extra.cc && %run %t 2>&1
106efa4d6cf9bb214a5e8ddbb224a69b38c4ae6de6Alexey Samsonov// RUN: %clangxx_asan -fsanitize-blacklist=%tmp -O2 %s -o %t \
112d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// RUN: %p/Helpers/blacklist-extra.cc && %run %t 2>&1
126efa4d6cf9bb214a5e8ddbb224a69b38c4ae6de6Alexey Samsonov// RUN: %clangxx_asan -fsanitize-blacklist=%tmp -O3 %s -o %t \
132d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// RUN: %p/Helpers/blacklist-extra.cc && %run %t 2>&1
145f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany
15dcf154d08f770f7b683ebe58c80603029a773c68Alexey Samsonov// badGlobal is accessed improperly, but we blacklisted it. Align
16dcf154d08f770f7b683ebe58c80603029a773c68Alexey Samsonov// it to make sure memory past the end of badGlobal will be in
17dcf154d08f770f7b683ebe58c80603029a773c68Alexey Samsonov// the same page.
18dcf154d08f770f7b683ebe58c80603029a773c68Alexey Samsonov__attribute__((aligned(16))) int badGlobal;
195f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryanyint readBadGlobal() {
205f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany  return (&badGlobal)[1];
215f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany}
225f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany
235f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// A function which is broken, but excluded in the blacklist.
245f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryanyint brokenFunction(int argc) {
255f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany  char x[10] = {0};
265f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany  return x[argc * 10];  // BOOM
275f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany}
285f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany
295f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// This function is defined in Helpers/blacklist-extra.cc, a source file which
305f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// is blacklisted by name
315f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryanyint externalBrokenFunction(int x);
325f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany
335f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryanyint main(int argc, char **argv) {
345f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany  brokenFunction(argc);
355f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany  int x = readBadGlobal();
365f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany  externalBrokenFunction(argc);
375f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany  return 0;
385f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany}
39