From 790058e1a89b979dc475be12952132dcc30e6ade Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Tue, 10 Feb 2026 11:27:11 +0000 Subject: Remove debug instructions; remove cdb wrapper for tcpto We need to check for size == 0 before mmapping tcpto[6], because 0 means "no match" for us but failure for mmap. So the wrapper isn't good enough; toss it and call fstat and mmap directly. And with that, we should be good, more or less. --- src/qmail-remote/qmailr_tcpto.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/qmail-remote/qmailr_tcpto.c') diff --git a/src/qmail-remote/qmailr_tcpto.c b/src/qmail-remote/qmailr_tcpto.c index f90d1d0..3b7ffeb 100644 --- a/src/qmail-remote/qmailr_tcpto.c +++ b/src/qmail-remote/qmailr_tcpto.c @@ -1,15 +1,18 @@ /* ISC license. */ +#include + #include #include #include #include #include +#include +#include #include #include #include -#include #include #include @@ -41,15 +44,19 @@ int qmailr_tcpto_match (char const *ip, int is6) uint32_t iplen = is6 ? 16 : 4 ; uint32_t width = iplen + 12 ; int r = 0 ; + char const *map ; char const *p ; - cdb c ; /* XXX: not a cdb, we're just using the mmap wrapper */ + struct stat st ; int fd = openc_read(file) ; if (fd == -1) return -1 ; if (fd_lock(fd, 0, 0) == -1) goto err ; - if (!cdb_init_fromfd(&c, fd)) goto err ; - if (c.size % width) goto errproto ; - p = bsearch(ip, c.map, c.size / width, width, is6 ? &qmailr_memcmp16 : &qmailr_memcmp4) ; + if (fstat(fd, &st) == -1) goto err ; + if (!st.st_size) goto end ; + if (st.st_size % width) goto errproto ; + map = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0) ; + if (map == MAP_FAILED) goto err ; + p = bsearch(ip, map, st.st_size / width, width, is6 ? &qmailr_memcmp16 : &qmailr_memcmp4) ; if (p) { if (p[iplen] >= 2) @@ -62,7 +69,7 @@ int qmailr_tcpto_match (char const *ip, int is6) r = tai_sec(&when) < ((60 + (getpid() & 31)) << 6) ; /* don't ask me, ask djb */ } } - cdb_free(&c) ; + end: fd_close(fd) ; return r ; -- cgit v1.3.1