Make sodium_free() callable even if protection is PROT_NONE.

Reported by @stouset, thanks!
This commit is contained in:
Frank Denis 2014-12-07 14:52:44 -08:00
parent b53f5c7f74
commit 5e364632e0
2 changed files with 2 additions and 2 deletions

View File

@ -429,6 +429,7 @@ sodium_free(void *ptr)
return;
}
canary_ptr = ((unsigned char *) ptr) - sizeof canary;
sodium_mprotect_readwrite(ptr);
if (sodium_memcmp(canary_ptr, canary, sizeof canary) != 0) {
_out_of_bounds();
}
@ -436,7 +437,6 @@ sodium_free(void *ptr)
base_ptr = unprotected_ptr - page_size * 2U;
memcpy(&unprotected_size, base_ptr, sizeof unprotected_size);
total_size = page_size + page_size + unprotected_size + page_size;
_mprotect_readwrite(base_ptr, total_size);
#ifndef HAVE_PAGE_PROTECTION
if (sodium_memcmp(unprotected_ptr + unprotected_size,
canary, sizeof canary) != 0) {

View File

@ -50,7 +50,7 @@ int main(void)
buf = sodium_malloc(size);
assert(buf != NULL);
memset(buf, i, size);
sodium_mprotect_readonly(buf);
sodium_mprotect_noaccess(buf);
sodium_free(buf);
}
printf("OK\n");