unit-tests: Use allocated listener instead of stack object in exchange tests
When using the statement expression and a stack object along with clang-11 and libasan, we get quite a lot of errors about reading invalid memory. This is due to clang making the actual listener_t local to the block, such that the access outside of the macros using _assert_payload is (correctly) considered an error. By using a heap allocated object, we can destroy it once the listener returns FALSE (cleaning up properly), and since bus_t does not touch the listener after that, we don't get any errors from libasan. Co-authored-by: Tobias Brunner <[email protected]>
This commit is contained in:
committed by
Tobias Brunner
co-authored by
Tobias Brunner
parent
bdc7f84a23
commit
996f557c40
@@ -22,7 +22,7 @@
|
|||||||
#include <bio/bio_reader.h>
|
#include <bio/bio_reader.h>
|
||||||
#include <bio/bio_writer.h>
|
#include <bio/bio_writer.h>
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* FIXME: Since we don't have the server side yet, this is kind of a hack!!!
|
* FIXME: Since we don't have the server side yet, this is kind of a hack!!!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -37,15 +37,18 @@ static bool add_notify(listener_t *listener, ike_sa_t *ike_sa,
|
|||||||
{
|
{
|
||||||
message->add_notify(message, FALSE, IKEV2_MESSAGE_ID_SYNC_SUPPORTED,
|
message->add_notify(message, FALSE, IKEV2_MESSAGE_ID_SYNC_SUPPORTED,
|
||||||
chunk_empty);
|
chunk_empty);
|
||||||
|
free(listener);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define add_notify_to_ike_auth() ({ \
|
#define add_notify_to_ike_auth() ({ \
|
||||||
listener_t _notify_listener = { \
|
listener_t *_notify_listener; \
|
||||||
|
INIT(_notify_listener, \
|
||||||
.message = add_notify, \
|
.message = add_notify, \
|
||||||
}; \
|
); \
|
||||||
exchange_test_helper->add_listener(exchange_test_helper, &_notify_listener); \
|
exchange_test_helper->add_listener(exchange_test_helper, _notify_listener); \
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -178,6 +178,8 @@ bool exchange_test_asserts_message(listener_t *listener, ike_sa_t *ike_sa,
|
|||||||
assert_message_rule(this, message, &this->rules[i]);
|
assert_message_rule(this, message, &this->rules[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
free(this->rules);
|
||||||
|
free(this);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|||||||
@@ -350,16 +350,18 @@ bool exchange_test_asserts_message(listener_t *this, ike_sa_t *ike_sa,
|
|||||||
|
|
||||||
#define _assert_payload(dir, c, ...) ({ \
|
#define _assert_payload(dir, c, ...) ({ \
|
||||||
listener_message_rule_t _rules[] = { __VA_ARGS__ }; \
|
listener_message_rule_t _rules[] = { __VA_ARGS__ }; \
|
||||||
listener_message_assert_t _listener = { \
|
listener_message_assert_t *_listener; \
|
||||||
|
INIT(_listener, \
|
||||||
.listener = { .message = exchange_test_asserts_message, }, \
|
.listener = { .message = exchange_test_asserts_message, }, \
|
||||||
.file = __FILE__, \
|
.file = __FILE__, \
|
||||||
.line = __LINE__, \
|
.line = __LINE__, \
|
||||||
.incoming = streq(dir, "IN") ? TRUE : FALSE, \
|
.incoming = streq(dir, "IN") ? TRUE : FALSE, \
|
||||||
.count = c, \
|
.count = c, \
|
||||||
.rules = _rules, \
|
.rules = malloc(sizeof(_rules)), \
|
||||||
.num_rules = countof(_rules), \
|
.num_rules = countof(_rules), \
|
||||||
}; \
|
); \
|
||||||
exchange_test_helper->add_listener(exchange_test_helper, &_listener.listener); \
|
memcpy(_listener->rules, _rules, sizeof(_rules)); \
|
||||||
|
exchange_test_helper->add_listener(exchange_test_helper, &_listener->listener); \
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user