Commit d2b3a26b authored by Pavel Emelyanov's avatar Pavel Emelyanov

zdtm: Don't allocate memory to mprotect with calloc

On my FC17 box calloc calls brk() and the subsequent mprotect(PROT_EXEC)
fails with EACCESS. Using mmap is safer here.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent f8a12079
...@@ -87,8 +87,8 @@ int main(int argc, char ** argv) ...@@ -87,8 +87,8 @@ int main(int argc, char ** argv)
exit(1); exit(1);
} }
ptr = calloc(pagesize, NUM_MPROTS + 1); ptr = mmap(NULL, pagesize * (NUM_MPROTS + 1), PROT_NONE, MAP_PRIVATE | MAP_ANON, 0, 0);
if (!ptr) { if (ptr == MAP_FAILED) {
err("calloc failed: %m"); err("calloc failed: %m");
return -1; return -1;
} }
...@@ -100,7 +100,6 @@ int main(int argc, char ** argv) ...@@ -100,7 +100,6 @@ int main(int argc, char ** argv)
if (mprotect(ptr_aligned + pagesize * i, if (mprotect(ptr_aligned + pagesize * i,
pagesize / 2, prots[i]) < 0) { pagesize / 2, prots[i]) < 0) {
err("mprotect failed: %m"); err("mprotect failed: %m");
free(ptr);
exit(1); exit(1);
} }
...@@ -113,6 +112,5 @@ int main(int argc, char ** argv) ...@@ -113,6 +112,5 @@ int main(int argc, char ** argv)
pass(); pass();
out: out:
free(ptr);
return 0; return 0;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment