From 914cd2b27257627f42e70ebdcb26501b581ad40d Mon Sep 17 00:00:00 2001 From: dmiller Date: Fri, 30 Sep 2022 20:03:37 +0000 Subject: [PATCH] Fix stdnse.tohex not adding separators. Fixes #2531 --- nselib/stdnse.lua | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/nselib/stdnse.lua b/nselib/stdnse.lua index d5a9dda6a..d16339d20 100644 --- a/nselib/stdnse.lua +++ b/nselib/stdnse.lua @@ -314,14 +314,11 @@ function tohex( s, options ) -- format hex if we got a separator if separator then local group = options.group or 2 - local left = #hex - gsub(hex, ".", function(h) - left = left - 1 - if left % group == 0 and left > 0 then - return h .. separator - end - return h - end) + local subs = 0 + local pat = "(%x)(" .. rep("[^:]", group) .. ")%f[\0:]" + repeat + hex, subs = gsub(hex, pat, "%1:%2") + until subs == 0 end return hex