1 | // Test that we don't crash for vtable pointers with an invalid ptrauth |
2 | // signature which includes unauthenticated vtable pointers. |
3 | |
4 | // RUN: %clangxx -frtti -fsanitize=vptr -fno-sanitize-recover=vptr -g %s -O3 -o %t |
5 | // RUN: not %run %t 2>&1 | FileCheck %s |
6 | |
7 | // TODO(yln): introduce 'ptrauth' lit feature |
8 | // REQUIRES: stable-runtime, cxxabi, target={{arm64e.*}} |
9 | |
10 | #include <typeinfo> |
11 | #include <ptrauth.h> |
12 | |
13 | struct S { |
14 | S() {} |
15 | ~S() {} |
16 | virtual int v() { return 0; } |
17 | }; |
18 | |
19 | int main(int argc, char **argv) { |
20 | S Obj; |
21 | void *Ptr = &Obj; |
22 | void **VtablePtrPtr = reinterpret_cast<void **>(&Obj); |
23 | // Hack Obj: the unauthenticated Vtable ptr will trigger an auth failure in the runtime. |
24 | void *UnauthenticatedVtablePtr = ptrauth_strip(*VtablePtrPtr, 0); |
25 | *VtablePtrPtr = UnauthenticatedVtablePtr; |
26 | |
27 | // CHECK: vptr-ptrauth-unauthenticated.cpp:[[@LINE+3]]:16: runtime error: member call on address [[PTR:0x[0-9a-f]*]] which does not point to an object of type 'S' |
28 | // CHECK: [[PTR]]: note: object has invalid vptr |
29 | S *Ptr2 = reinterpret_cast<S *>(Ptr); |
30 | return Ptr2->v(); |
31 | } |
32 | |