Reject publication when the initial member profile signature cannot be bound

This commit is contained in:
evgeny committed 2026-10-27 04:34:57 +01:00
1 parent 956febe1d7
commit 1ce58cbeac
2 files changed
+17 -1

No files matched your search

+1 -1
View File
@@ -314,7 +314,7 @@ test_chat_setting_LDADD = $(LIBUTUN) $(COMMON_LIBS)
test_chat_setting_LDFLAGS = -Wl,--wrap=chat_local_apply_settings
test_chat_channel_SOURCES = test_chat_channel.c
test_chat_channel_LDADD = $(LIBUTUN) $(COMMON_LIBS)
test_chat_channel_LDFLAGS = -Wl,--wrap=EVP_DigestSign
test_chat_channel_LDFLAGS = -Wl,--wrap=EVP_DigestSign -Wl,--wrap=sqlite3_bind_blob
else
test_socket_monitor_LDFLAGS += -Wl,--wrap=read
endif
+16
View File
@@ -16,6 +16,17 @@
static unsigned fail_sign_number, channel_events;
static struct UTUN_INSTANCE* active;
static sqlite3* reader;
static int fail_profile_binding;
extern int __real_sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int, void (*)(void*));
int __wrap_sqlite3_bind_blob(sqlite3_stmt* st, int index, const void* value, int length, void (*destroy)(void*)) {
const char* prefix = "INSERT INTO \"peers_";
if (fail_profile_binding && index == 6 && !strncmp(sqlite3_sql(st), prefix, strlen(prefix))) {
fail_profile_binding = 0; DEBUG_WARN(DEBUG_CATEGORY_CHAT_SYNC, "channel test: injected root profile signature bind failure");
return SQLITE_NOMEM;
}
return __real_sqlite3_bind_blob(st, index, value, length, destroy);
}
extern int __real_EVP_DigestSign(EVP_MD_CTX*, unsigned char*, size_t*, const unsigned char*, size_t);
int __wrap_EVP_DigestSign(EVP_MD_CTX* ctx, unsigned char* signature, size_t* length, const unsigned char* data, size_t size) {
@@ -64,6 +75,11 @@ int main(void) {
DEBUG_INFO(DEBUG_CATEGORY_CHAT_SYNC, "channel test: after signature fault channels=%d events=%u", channels(), channel_events);
assert(!fail_sign_number && !channels() && !channel_events);
chat_core_create_channel_auto(inst, "successful retry"); assert(channels() == 1 && channel_events == 1);
fail_profile_binding = 1;
uint64_t created = chat_core_create_channel_auto(inst, "root profile SQL failure");
DEBUG_INFO(DEBUG_CATEGORY_CHAT_SYNC, "channel test: profile bind failure ID=%llu channels=%d events=%u",
(unsigned long long)created, channels(), channel_events);
assert(!fail_profile_binding && !created && channels() == 1 && channel_events == 1);
utun_instance_destroy(inst); active = NULL; assert(channels() == 1 && sqlite3_close(reader) == SQLITE_OK); reader = NULL;
uasync_poll(ua, 0); uasync_destroy(ua, 0); assert(u_get_allocated_count() == baseline);
DEBUG_INFO(DEBUG_CATEGORY_CHAT_SYNC, "PASS channel creation: failed root signature leaves no channel/event; retry publishes valid membership after commit");