null2.c
up: index
prev: null1.c
next: null3.c
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include "capprint.h"
int main()
{
// C0
int *p = NULL;
fprintf(stderr,"NULL: %s, which is %s\n", null_sptr(p), isnulls(p));
// as intptr_t
intptr_t ip = (intptr_t)p;
fprintf(stderr,"NULL as intptr_t: %s\n", null_siptr(ip));
fprintf(stderr,"NULL as intptr_t cast to long: %ld\n", (long)ip);
// assigning runtime 0 value to pointer
long x = 99;
p = (int*)(x-99);
fprintf(stderr,"assigned: %s, which is %s\n", null_sptr(p), isnulls(p));
}
Experimental data (what does this mean?)
cerberus-cheri
cerberus-cheri-no-pnvi
cerberus-cheri-revocation
cerberus-cheri-revocation-no-pnvi
cerberus-cheri-cornucopia
cerberus-cheri-cornucopia-no-pnvi NULL: 0x0 [,0x0 - 0xffffffffffffffff] (invalid), which is null
NULL as intptr_t: 0x0 [,0x0 - 0xffffffffffffffff] (invalid)
NULL as intptr_t cast to long: 0
assigned: 0x0 [,0x0 - 0xffffffffffffffff] (invalid), which is null
clang-morello-O0-bounds-conservative
clang-morello-O3-bounds-conservative
clang-morello-O0-bounds-references-only
clang-morello-O0-bounds-subobject-safe
clang-morello-O3-bounds-subobject-safe
clang-morello-O0-bounds-aggressive
clang-morello-O0-bounds-very-aggressive
clang-morello-O0-bounds-everywhere-unsafe
clang-riscv-O0-bounds-conservative
clang-riscv-O3-bounds-conservative
clang-riscv-O0-bounds-references-only
clang-riscv-O0-bounds-subobject-safe
clang-riscv-O3-bounds-subobject-safe
clang-riscv-O0-bounds-aggressive
clang-riscv-O0-bounds-very-aggressive
clang-riscv-O0-bounds-everywhere-unsafe tests/cheri/null2.c:21:9: warning: cast from provenance-free integer type to pointer type will give pointer that can not be dereferenced [-Wcheri-capability-misuse]
p = (int*)(x-99);
^
1 warning generated.
NULL: 0 [,0 - 0xffffffffffffffff] (invalid), which is null
NULL as intptr_t: 0 [,0 - 0xffffffffffffffff] (invalid)
NULL as intptr_t cast to long: 0
assigned: 0 [,0 - 0xffffffffffffffff] (invalid), which is null
gcc-morello-O0
gcc-morello-O3 tests/cheri/null2.c: In function 'main':
tests/cheri/null2.c:21:9: warning: cast from provenance-free integer type to pointer type will give pointer that can not be dereferenced [-Wcheri-capability-misuse]
21 | p = (int*)(x-99);
| ^
tests/cheri/null2.c:21:9: note: insert cast to intptr_t to silence this warning
NULL: 0x0 [,0x0-0xffffffffffffffff] (invalid), which is null
NULL as intptr_t: 0x0 [,0x0-0xffffffffffffffff] (invalid)
NULL as intptr_t cast to long: 0
assigned: 0x0 [,0x0-0xffffffffffffffff] (invalid), which is null