Debian Codegraph @

crt/s2n/tests/unit/s2n_seccomp_failure_test.c

raw symbols SCIP
1 /*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at
7 *
8 * http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
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 /* The seccomp filter allows fstat */
53 struct stat st = { 0 };
54 EXPECT_SUCCESS(fstat(0, &st));
55 s2n_fstat_success = true;
56
57 /* The seccomp filter does NOT allow open */
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 }