Dmitry V. Levin
48321344d7
* util.c (umovestr): Check the right address. * tests/umovestr.c: New file. * tests/umovestr2.c: Likewise. * tests/umovestr.expected: Likewise. * tests/umovestr.test: New test. * tests/umovestr2.test: Likewise. * tests/Makefile.am (check_PROGRAMS): Add umovestr and umovestr2. (TESTS): Add umovestr.test and umovestr2.test. (EXTRA_DIST): Add umovestr.expected. * tests/.gitignore: Add umovestr and umovestr2. Reported-by: Josef T. Burger <bolo@cs.wisc.edu>
27 lines
532 B
C
27 lines
532 B
C
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <sys/mman.h>
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
const size_t page_len = sysconf(_SC_PAGESIZE);
|
|
const size_t tail_len = 257;
|
|
|
|
if (tail_len >= page_len)
|
|
return 77;
|
|
|
|
void *p = mmap(NULL, page_len * 2, PROT_READ | PROT_WRITE,
|
|
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
|
if (p == MAP_FAILED || mprotect(p + page_len, page_len, PROT_NONE))
|
|
return 77;
|
|
|
|
memset(p, 0, page_len);
|
|
char *addr = p + page_len - tail_len;
|
|
memset(addr, '/', tail_len - 1);
|
|
if (chdir(addr))
|
|
return 77;
|
|
|
|
return 0;
|
|
}
|