Skip to content

Commit de2500f

Browse files
committed
benchmark: Replace assert with EXPECT
1 parent ea2a2fb commit de2500f

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/bin/seccomp/seccomp_trap.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ int user_trap_syscalls(const int *nrs, size_t length, unsigned int flags) {
114114
filter[i++] = (struct sock_filter) BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_KILL_PROCESS);
115115

116116
// now with the syscall nr still loaded, dynamically add checks for all syscall nrs we want to intercept
117-
// Warning: If there are more nrs than MAX_FILTER_SIZE - 3, we may omit some system calls
118-
// But this is still more sane than writing out of bounds
119117
for (int j = 0; j < length; ++j) {
120118
// jump if equal
121119
filter[i].code = (unsigned short) BPF_JMP+BPF_JEQ+BPF_K;

tests/benchmark.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#define _GNU_SOURCE
22

3-
#include <assert.h>
43
#include <fcntl.h>
54
#include <linux/openat2.h>
65
#include <math.h>
@@ -10,20 +9,22 @@
109
#include <time.h>
1110
#include <unistd.h>
1211

12+
#define EXPECT(cond) if (!(cond)) { fprintf(stderr, "Failed assert: %s\n", #cond); exit(EXIT_FAILURE); }
13+
1314
void check_correct_fd(int fd) {
14-
assert(fd >= 0);
15+
EXPECT(fd >= 0);
1516
static char c;
1617

1718
// we should be able to read from the file descriptor
1819
ssize_t r = read(fd, &c, 1);
19-
assert(r);
20+
EXPECT(r);
2021

2122
// the read char should be either 'a' or 'b' or 'c', depending on whether system calls are intercepted and which file is read
22-
assert((c == 'a') || (c == 'b') || (c == 'c'));
23+
EXPECT((c == 'a') || (c == 'b') || (c == 'c'));
2324

2425
// close the descriptor again
2526
int a = close(fd);
26-
assert(!a);
27+
EXPECT(!a);
2728
}
2829

2930
int do_openat(const char *filename) {

0 commit comments

Comments
 (0)