I am trying to unit test C/glibc code that I know results in undefined behaviour, but will fail with SEGV given appropriate the compiler options. Something like:
void will_fail(char *bar) {
bar[10000] = 'X';
}
void test_will_fail(void) {
will_fail("foo"); // How can I handle this failing?
}
Is there a way to trap the next SEGV, possibly GCC specific or asm? If it needs a separate address space (fork/exec), what is a good way to tell that the spawned process ended with SEGV?
I am using c11 / x86-64 / glibc 2.26 / gcc 7.2.0 with -fsanitize=address / CUnit (which does not use a separate address space for unit tests). The only hard requirement is to stay in the realm of C.
Any guidance is much appreciated. Thanks!
Aucun commentaire:
Enregistrer un commentaire