Fixes asyncftpclient multiline reading, fixes #4684 (#13242)

Previously, the 4th character of `result` was checked for `'-'` every time, instead of each new line.

Also made it work for taint mode.
This commit is contained in:
hlaaftana 2020-01-24 02:18:16 +03:00 • committed by Andreas Rumpf
commit 4656580b54

View file

@ -131,12 +131,13 @@ type
const multiLineLimit = 10000 const multiLineLimit = 10000
proc expectReply(ftp: AsyncFtpClient): Future[TaintedString] {.async.} = proc expectReply(ftp: AsyncFtpClient): Future[TaintedString] {.async.} =
result = await ftp.csock.recvLine() var line = await ftp.csock.recvLine()
result = TaintedString(line)
var count = 0 var count = 0
while result[3] == '-': while line[3] == '-':
## Multi-line reply. ## Multi-line reply.
let line = await ftp.csock.recvLine() line = await ftp.csock.recvLine()
result.add("\n" & line) string(result).add("\n" & line)
count.inc() count.inc()
if count >= multiLineLimit: if count >= multiLineLimit:
raise newException(ReplyError, "Reached maximum multi-line reply count.") raise newException(ReplyError, "Reached maximum multi-line reply count.")
@ -178,7 +179,7 @@ proc connect*(ftp: AsyncFtpClient) {.async.} =
await ftp.csock.connect(ftp.address, ftp.port) await ftp.csock.connect(ftp.address, ftp.port)
var reply = await ftp.expectReply() var reply = await ftp.expectReply()
if reply.startsWith("120"): if string(reply).startsWith("120"):
# 120 Service ready in nnn minutes. # 120 Service ready in nnn minutes.
# We wait until we receive 220. # We wait until we receive 220.
reply = await ftp.expectReply() reply = await ftp.expectReply()