@@ -211,17 +211,22 @@ local function _encode_name(s)
211211 return char (# s ) .. s
212212end
213213
214+
214215local function _decode_string (buf , pos )
215216 local slen = byte (buf , pos )
217+
216218 if slen == 0 then
217219 return " " , pos + 1
218220 end
221+
219222 if pos + 1 + slen >= # buf then
220223 return nil , ' truncated'
221224 end
225+
222226 return sub (buf , pos + 1 , pos + slen ), pos + slen + 1
223227end
224228
229+
225230local function _decode_name (buf , pos )
226231 local labels = {}
227232 local nptrs = 0
@@ -501,34 +506,43 @@ local function parse_section(answers, section, buf, start_pos, size,
501506 return nil , " bad NAPTR record value length: " .. len
502507 end
503508
504- local hi = byte (buf , pos )
505- local lo = byte (buf , pos + 1 )
506- ans .order = lshift (hi , 8 ) + lo
509+ local order_hi = byte (buf , pos )
510+ local order_lo = byte (buf , pos + 1 )
511+ ans .order = lshift (order_hi , 8 ) + order_lo
507512
508- hi = byte (buf , pos + 2 )
509- lo = byte (buf , pos + 3 )
510- ans .preference = lshift (hi , 8 ) + lo
513+ local preference_hi = byte (buf , pos + 2 )
514+ local preference_lo = byte (buf , pos + 3 )
515+ ans .preference = lshift (preference_hi , 8 ) + preference_lo
511516
512- local str , p = _decode_string (buf , pos + 4 )
513- if not str then return nil , pos end
514- ans .flags = str
517+ local flags_str , p = _decode_string (buf , pos + 4 )
518+ if not flags_str then
519+ return nil , pos
520+ end
521+ ans .flags = flags_str
515522
516- str , p = _decode_string (buf , p )
517- if not str then return nil , pos end
518- ans .services = str
523+ local services_str , p = _decode_string (buf , p )
524+ if not services_str then
525+ return nil , pos
526+ end
527+ ans .services = services_str
519528
520- str , p = _decode_string (buf , p )
521- if not str then return nil , pos end
522- ans .regexp = str
529+ local regexp_str , p = _decode_string (buf , p )
530+ if not regexp_str then
531+ return nil , pos
532+ end
533+ ans .regexp = regexp_str
523534
524535 if p - pos < len then
525- str ,p = _decode_name (buf , p )
526- if not str then return nil , pos end
527- ans .replacements = str
536+ local replacements_str ,p = _decode_name (buf , p )
537+ if not replacements_str
538+ then return nil , pos
539+ end
540+ ans .replacements = replacements_str
528541 end
529542
530543 if p - pos ~= len then
531- return nil , format (" bad NAPTR record length: %d ~= %d" , p - pos , len )
544+ return nil , format (" bad NAPTR record length: %d ~= %d" ,
545+ p - pos , len )
532546 end
533547
534548 pos = p
0 commit comments