From 0dbf3c9b160dba9820185d6cd41c1ced436fb39e Mon Sep 17 00:00:00 2001 From: dmiller Date: Mon, 14 May 2018 18:19:10 +0000 Subject: [PATCH] Strip trailing whitespace when parsing torrent files. Fixes #1211 --- nselib/bittorrent.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nselib/bittorrent.lua b/nselib/bittorrent.lua index 8f1f2ce6b..c8f1916b7 100644 --- a/nselib/bittorrent.lua +++ b/nselib/bittorrent.lua @@ -154,8 +154,7 @@ bdecode = function(buf) cur.ref.type="list" cur.ref.start = pos - while true do - if pos == len or (len-pos)==-1 then break end + while pos <= len do if cur.type == "list" then -- next element is a string @@ -205,6 +204,10 @@ bdecode = function(buf) cur = stack[#stack] if not cur then return nil, "Problem with list closure:", pos end pos = pos+1 + + -- trailing whitespace + elseif string.match(buf, "%s*$", pos) then + pos = len+1 else return nil, "Unknown type found.", pos end