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 65f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// RUN: %clangxx_asan -mllvm -asan-blacklist=%tmp -m64 -O0 %s -o %t \ 75f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// RUN: %p/Helpers/blacklist-extra.cc && %t 2>&1 85f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// RUN: %clangxx_asan -mllvm -asan-blacklist=%tmp -m64 -O1 %s -o %t \ 95f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// RUN: %p/Helpers/blacklist-extra.cc && %t 2>&1 105f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// RUN: %clangxx_asan -mllvm -asan-blacklist=%tmp -m64 -O2 %s -o %t \ 115f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// RUN: %p/Helpers/blacklist-extra.cc && %t 2>&1 125f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// RUN: %clangxx_asan -mllvm -asan-blacklist=%tmp -m64 -O3 %s -o %t \ 135f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// RUN: %p/Helpers/blacklist-extra.cc && %t 2>&1 145f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// RUN: %clangxx_asan -mllvm -asan-blacklist=%tmp -m32 -O0 %s -o %t \ 155f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// RUN: %p/Helpers/blacklist-extra.cc && %t 2>&1 165f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// RUN: %clangxx_asan -mllvm -asan-blacklist=%tmp -m32 -O1 %s -o %t \ 175f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// RUN: %p/Helpers/blacklist-extra.cc && %t 2>&1 185f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// RUN: %clangxx_asan -mllvm -asan-blacklist=%tmp -m32 -O2 %s -o %t \ 195f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// RUN: %p/Helpers/blacklist-extra.cc && %t 2>&1 205f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// RUN: %clangxx_asan -mllvm -asan-blacklist=%tmp -m32 -O3 %s -o %t \ 215f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// RUN: %p/Helpers/blacklist-extra.cc && %t 2>&1 225f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany 235f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// badGlobal is accessed improperly, but we blacklisted it. 245f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryanyint badGlobal; 255f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryanyint readBadGlobal() { 265f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany return (&badGlobal)[1]; 275f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany} 285f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany 295f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// A function which is broken, but excluded in the blacklist. 305f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryanyint brokenFunction(int argc) { 315f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany char x[10] = {0}; 325f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany return x[argc * 10]; // BOOM 335f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany} 345f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany 355f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// This function is defined in Helpers/blacklist-extra.cc, a source file which 365f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany// is blacklisted by name 375f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryanyint externalBrokenFunction(int x); 385f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany 395f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryanyint main(int argc, char **argv) { 405f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany brokenFunction(argc); 415f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany int x = readBadGlobal(); 425f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany externalBrokenFunction(argc); 435f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany return 0; 445f799c78e5b1bd8105bab77a0935f27ee808dc97Kostya Serebryany} 45