From 4eb923f9723f1c25c405d576de8ead4f7dad8097 Mon Sep 17 00:00:00 2001 From: buffermet <29265684+buffermet@users.noreply.github.com> Date: Sun, 16 Feb 2025 13:53:54 +0100 Subject: [PATCH] Fix float64/int64 to uint64 conversion from JS environment --- modules/dns_proxy/dns_proxy_js_query.go | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/modules/dns_proxy/dns_proxy_js_query.go b/modules/dns_proxy/dns_proxy_js_query.go index 535a153f..263ca213 100644 --- a/modules/dns_proxy/dns_proxy_js_query.go +++ b/modules/dns_proxy/dns_proxy_js_query.go @@ -5,6 +5,7 @@ import ( "fmt" "math" "math/big" + "reflect" "github.com/bettercap/bettercap/v2/log" "github.com/bettercap/bettercap/v2/session" @@ -139,11 +140,25 @@ func jsPropToUint32(obj map[string]interface{}, key string) uint32 { } func jsPropToUint64(obj map[string]interface{}, key string) uint64 { - if f, ok := obj[key].(float64); ok { - bigInt := new(big.Float).SetFloat64(f) - v, _ := bigInt.Uint64() - if v >= 0 { - return v + prop, found := obj[key] + if found { + switch reflect.TypeOf(prop).String() { + case "float64": + if f, ok := prop.(float64); ok { + bigInt := new(big.Float).SetFloat64(f) + v, _ := bigInt.Uint64() + if v >= 0 { + return v + } + } + break + case "int64": + if v, ok := prop.(int64); ok { + if v >= 0 { + return uint64(v) + } + } + break } } log.Error("error converting JS property to uint64 where key is: %s", key)