| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include <signal.h> |
| 17 |
#include <stdio.h> |
| 18 |
#include <sys/stat.h> |
| 19 |
|
| 20 |
#include "s2n_test.h" |
| 21 |
#include "testlib/s2n_testlib.h" |
| 22 |
|
| 23 |
bool s2n_fstat_success = false; |
| 24 |
bool s2n_open_success = false; |
| 25 |
|
| 26 |
void s2n_detect_open_violation(int sig) |
| 27 |
{ |
| 28 |
EXPECT_EQUAL(sig, SIGSYS); |
| 29 |
|
| 30 |
EXPECT_TRUE(s2n_fstat_success); |
| 31 |
EXPECT_FALSE(s2n_open_success); |
| 32 |
|
| 33 |
END_TEST_PRINT(); |
| 34 |
exit(0); |
| 35 |
} |
| 36 |
|
| 37 |
int main(int argc, char **argv) |
| 38 |
{ |
| 39 |
BEGIN_TEST(); |
| 40 |
|
| 41 |
if (!s2n_is_seccomp_supported()) { |
| 42 |
END_TEST(); |
| 43 |
} |
| 44 |
|
| 45 |
const struct sigaction action = { |
| 46 |
.sa_handler = s2n_detect_open_violation, |
| 47 |
}; |
| 48 |
EXPECT_EQUAL(sigaction(SIGSYS, &action, NULL), 0); |
| 49 |
|
| 50 |
EXPECT_OK(s2n_seccomp_init()); |
| 51 |
|
| 52 |
|
| 53 |
struct stat st = { 0 }; |
| 54 |
EXPECT_SUCCESS(fstat(0, &st)); |
| 55 |
s2n_fstat_success = true; |
| 56 |
|
| 57 |
|
| 58 |
FILE *file = fopen(S2N_DEFAULT_TEST_CERT_CHAIN, "r"); |
| 59 |
s2n_open_success = true; |
| 60 |
EXPECT_NOT_NULL(file); |
| 61 |
|
| 62 |
FAIL_MSG("test unexpectedly succeeded"); |
| 63 |
} |