From 34e8e2ad8eb18492c0a64a3794356321637eda47 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Thu, 1 Aug 2024 16:55:22 -0700 Subject: [PATCH] nostrdb: Fix issue where id tag filters are pushed as strings When creating filters, sometimes IDs are pushed as strings, so if there is ever a 0 byte, the id prematurely ends, causing the filter to not match Fixes: https://github.com/rust-nostr/nostr/issues/454 Signed-off-by: William Casarin --- nostrdb/src/nostrdb.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/nostrdb/src/nostrdb.c b/nostrdb/src/nostrdb.c index cdd335935..ad1a4f366 100644 --- a/nostrdb/src/nostrdb.c +++ b/nostrdb/src/nostrdb.c @@ -784,8 +784,18 @@ static int ndb_filter_add_element(struct ndb_filter *filter, union ndb_filter_el offset = el.integer; break; case NDB_FILTER_TAGS: - if (!cursor_push_c_str(&filter->data_buf, el.string)) + switch (current->field.elem_type) { + case NDB_ELEMENT_ID: + if (!cursor_push(&filter->data_buf, (unsigned char *)el.id, 32)) + return 0; + break; + case NDB_ELEMENT_STRING: + if (!cursor_push_c_str(&filter->data_buf, el.string)) + return 0; + break; + case NDB_ELEMENT_UNKNOWN: return 0; + } // push a pointer of the string in the databuf as an element break; }