Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions CHERIProvenanceOfPointer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include<cheri.h>
#include<stdio.h>

int main(){

int myArray[10];

int *ptr = &myArray[0]; // storing the pointer as a capability

//perform a capability safe operation - accessing a valid element

int myValue = *ptr;

// access within bounds

int *new_ptr = ptr + 5;

printf("valid value : %d\n", myValue);

return 0;

}
27 changes: 27 additions & 0 deletions pointerProvenanceIssue.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

#include<stdint.h>
#include<stdio.h>

int main () {

int myArray[10];

uintptr_t ptr = (uintptr_t)&myArray[0]; //storing the address as uintptr_t

//performing an invalid operation - accessing a non existent element

uintptr_r myPtr = ptr + sizeof(int)* 20;

//trying to accessing the memory using an invalid pointer

int myValue = *(int*)myPtr // no memory safety checks

printf("invalid value : %d\n ",myValue);


return 0;

}