mirror of
https://passt.top/passt
synced 2025-06-13 02:55:34 +02:00
Make assertions actually useful
There are some places in passt/pasta which #include <assert.h> and make various assertions. If we hit these something has already gone wrong, but they're there so that we a useful message instead of cryptic misbehaviour if assumptions we thought were correct turn out not to be. Except.. the glibc implementation of assert() uses syscalls that aren't in our seccomp filter, so we'll get a SIGSYS before it actually prints the message. Work around this by adding our own ASSERT() implementation using our existing err() function to log the message, and an abort(). The abort() probably also won't work exactly right with seccomp, but once we've printed the message, dying with a SIGSYS works just as well as dying with a SIGABRT. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
cc6d8286d1
commit
7a8ed9459d
7 changed files with 32 additions and 20 deletions
9
tcp.c
9
tcp.c
|
@ -288,7 +288,6 @@
|
|||
#include <sys/uio.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <linux/tcp.h> /* For struct tcp_info */
|
||||
|
||||
|
@ -588,7 +587,7 @@ static inline struct tcp_tap_conn *conn_at_idx(int index)
|
|||
{
|
||||
if ((index < 0) || (index >= TCP_MAX_CONNS))
|
||||
return NULL;
|
||||
assert(!(CONN(index)->c.spliced));
|
||||
ASSERT(!(CONN(index)->c.spliced));
|
||||
return CONN(index);
|
||||
}
|
||||
|
||||
|
@ -2695,7 +2694,7 @@ static void tcp_conn_from_sock(struct ctx *c, union epoll_ref ref,
|
|||
socklen_t sl;
|
||||
int s;
|
||||
|
||||
assert(ref.r.p.tcp.tcp.listen);
|
||||
ASSERT(ref.r.p.tcp.tcp.listen);
|
||||
|
||||
if (c->tcp.conn_count >= TCP_MAX_CONNS)
|
||||
return;
|
||||
|
@ -2937,7 +2936,7 @@ static void tcp_ns_sock_init4(const struct ctx *c, in_port_t port)
|
|||
struct in_addr loopback = { htonl(INADDR_LOOPBACK) };
|
||||
int s;
|
||||
|
||||
assert(c->mode == MODE_PASTA);
|
||||
ASSERT(c->mode == MODE_PASTA);
|
||||
|
||||
s = sock_l4(c, AF_INET, IPPROTO_TCP, &loopback, NULL, port, tref.u32);
|
||||
if (s >= 0)
|
||||
|
@ -2961,7 +2960,7 @@ static void tcp_ns_sock_init6(const struct ctx *c, in_port_t port)
|
|||
.tcp.index = idx };
|
||||
int s;
|
||||
|
||||
assert(c->mode == MODE_PASTA);
|
||||
ASSERT(c->mode == MODE_PASTA);
|
||||
|
||||
s = sock_l4(c, AF_INET6, IPPROTO_TCP, &in6addr_loopback, NULL, port,
|
||||
tref.u32);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue