From 5e64991296f081b2b30ce4d85171a21844c010ff Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Sun, 28 May 2023 11:07:10 +0200 Subject: [PATCH] Fix CHATHISTORY BETWEEN accidentally including a message too much Reported by progval in https://bugs.unrealircd.org/view.php?id=5952 --- src/modules/history_backend_mem.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/modules/history_backend_mem.c b/src/modules/history_backend_mem.c index 63067405f..e7210ef7a 100644 --- a/src/modules/history_backend_mem.c +++ b/src/modules/history_backend_mem.c @@ -1023,9 +1023,23 @@ static int hbm_return_between(HistoryResult *r, HistoryLogObject *h, HistoryFilt direction = hbm_return_between_figure_out_direction(h, filter); if (direction == 1) + { return hbm_return_after(r, h, filter); - else if (direction == 0) - return hbm_return_before(r, h, filter); + } else + if (direction == 0) + { + /* Create a temporary filter, swapping directions */ + char *x, *y; + HistoryFilter f; + memset(&f, 0, sizeof(f)); + f.cmd = HFC_BEFORE; + f.limit = filter->limit; + f.timestamp_a = filter->timestamp_b; + f.timestamp_b = filter->timestamp_a; + f.msgid_a = filter->msgid_b; + f.msgid_b = filter->msgid_a; + return hbm_return_after(r, h, &f); + } /* else direction is -1 which means not found / invalid */ return 0;