From 77b793a9f17466cd5202d407904d848923211ce4 Mon Sep 17 00:00:00 2001 From: Diego Date: Sat, 31 May 2025 18:13:25 -0300 Subject: [PATCH] fix: use direct TTL field access instead of pointer arithmetic Modern libunbound (1.4.20+) has a direct 'ttl' field in struct ub_result. The previous pointer arithmetic approach was fragile and often returned 0. This fix directly accesses r->ttl which is reliable and safe. Fixes TTL=0 issue with libunbound 1.19.2 and other modern versions. --- unbound.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/unbound.go b/unbound.go index 9b09152..6f876e8 100644 --- a/unbound.go +++ b/unbound.go @@ -47,11 +47,10 @@ struct ub_result *new_ub_result() { r = calloc(sizeof(struct ub_result), 1); return r; } -int ub_ttl(struct ub_result *r) { - int *p; - // Go to why_bogus add the pointer and then we will find the ttl, hopefully. - p = (int*) ((char*)r + offsetof(struct ub_result, why_bogus) + sizeof(char*)); - return (int)*p; +int ub_ttl(struct ub_result *r) { + // FIXED: Modern libunbound (1.4.20+) has a direct ttl field in struct ub_result + // No need for dangerous pointer arithmetic - just access r->ttl directly + return r->ttl; } */ import "C"