blob: 9ad6b94d9cf5db4667ab0c9fd27e52a2359e9231 [file] [log] [blame]
Dmitry V. Levin48321342015-03-31 18:52:57 +00001#include <string.h>
2#include <unistd.h>
3#include <sys/mman.h>
4
5int
6main(void)
7{
8 const size_t page_len = sysconf(_SC_PAGESIZE);
9 const size_t tail_len = 257;
10
11 if (tail_len >= page_len)
12 return 77;
13
14 void *p = mmap(NULL, page_len * 2, PROT_READ | PROT_WRITE,
15 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
16 if (p == MAP_FAILED || mprotect(p + page_len, page_len, PROT_NONE))
17 return 77;
18
19 memset(p, 0, page_len);
20 char *addr = p + page_len - tail_len;
21 memset(addr, '/', tail_len - 1);
22 if (chdir(addr))
23 return 77;
24
25 return 0;
26}