src/strutil_test.cc
// Take a string, and copy it into an allocated buffer where
// the byte immediately after the null termination character
// is read protected. Useful for testing, but doesn't support
// freeing the allocated pages.
Take a string, and copy it into an allocated buffer where
the byte immediately after the null termination character
is read protected. Useful for testing, but doesn't support
freeing the allocated pages.
Take a string and copy it into an allocated buffer where the byte immediately after the null termination character is read protected . Useful for testing but doesn ' t support freeing the allocated pages .
const char* CreateProtectedString(const char* str) {
  int pagesize = sysconf(_SC_PAGE_SIZE);
  void* buffer;
  char* buffer_str;
  if (posix_memalign(&buffer, pagesize, pagesize * 2) != 0) {
    perror("posix_memalign failed");
    assert(false);
  }
  buffer_str = (char*)buffer + pagesize;
  if (mprotect(buffer_str, pagesize, PROT_NONE) != 0) {
    perror("mprotect failed");
    assert(false);
  }
  buffer_str -= strlen(str) + 1;
  strcpy(buffer_str, str);
  return buffer_str;
}
const char * CreateProtectedString ( const char * str ) { int pagesize = sysconf ( _SC_PAGE_SIZE ) ; void * buffer ; char * buffer_str ; if ( posix_memalign ( & buffer , pagesize , pagesize * 2 ) != 0 ) { perror ( " " ) ; assert ( false ) ; } buffer_str = ( char * ) buffer + pagesize ; if ( mprotect ( buffer_str , pagesize , PROT_NONE ) != 0 ) { perror ( " " ) ; assert ( false ) ; } buffer_str -= strlen ( str ) + 1 ; strcpy ( buffer_str , str ) ; return buffer_str ; }
Take a string, and copy it into an allocated buffer where
the byte immediately after the null termination character
is read protected.
Take a string and copy it into an allocated buffer where the byte immediately after the null termination character is read protected .
// Allocate two pages of memory // Make the second page unreadable // Then move the test string into the very end of the first page