taldir

Directory service to resolve wallet mailboxes by messenger addresses
Log | Files | Refs | Submodules | README | LICENSE

commit ce2eb3af1858bc9ff8301054e0b56970093a465f
parent 165382975808378a5562b9e7f6177f922645f276
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date:   Wed, 28 Oct 2026 19:25:19 +0100

properly handle negative durations to 0

Diffstat:
Mpkg/taldir/taldir.go | 8+++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/pkg/taldir/taldir.go b/pkg/taldir/taldir.go @@ -272,7 +272,8 @@ func (t *Taldir) getSingleEntry(w http.ResponseWriter, r *http.Request) { t.Logger.Logf(LogDebug, "Found entry %v", entry) entryValidity := time.UnixMicro(entry.CreatedAt + entry.Duration) w.Header().Set("Content-Type", "application/json") - w.Write(fmt.Appendf(make([]byte, 0), "{\"target_uri\": \"%s\", \"valid_for\": { \"d_us\": %d }}", entry.TargetURI, time.Until(entryValidity).Microseconds())) + validFor := uint64(max(0, time.Until(entryValidity).Microseconds())) + w.Write(fmt.Appendf(make([]byte, 0), "{\"target_uri\": \"%s\", \"valid_for\": { \"d_us\": %d }}", entry.TargetURI, validFor)) return } w.WriteHeader(http.StatusNotFound) @@ -453,7 +454,7 @@ func (t *Taldir) validationRequest(w http.ResponseWriter, r *http.Request) { if validation.TargetURI != "" { entryValidFor = time.Until(time.UnixMicro(entry.CreatedAt + entry.Duration)).Microseconds() } - w.Write(fmt.Appendf(make([]byte, 0), "{\"valid_for\": { \"d_us\": %d }}", entryValidFor)) + w.Write(fmt.Appendf(make([]byte, 0), "{\"valid_for\": { \"d_us\": %d }}", uint64(max(0, entryValidFor)))) } func (t *Taldir) isRateLimited(hAlias string) (bool, error) { @@ -557,7 +558,8 @@ func (t *Taldir) registerRequest(w http.ResponseWriter, r *http.Request) { t.Logger.Logf(LogDebug, "Returning validity of entry") w.WriteHeader(http.StatusOK) w.Header().Set("Content-Type", "application/json") - w.Write(fmt.Appendf(make([]byte, 0), "{\"valid_for\": { \"d_us\": %d }}", time.Until(entryValidity).Microseconds())) + validFor := uint64(max(0, time.Until(entryValidity).Microseconds())) + w.Write(fmt.Appendf(make([]byte, 0), "{\"valid_for\": { \"d_us\": %d }}", validFor)) return } }