Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added fix for handling TaintedStrings in streams and httpclient #12969

Merged
merged 2 commits into from
Dec 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/pure/httpclient.nim
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ proc addFiles*(p: var MultipartData, xs: openArray[tuple[name, file: string]]):
let (_, fName, ext) = splitFile(file)
if ext.len > 0:
contentType = m.getMimetype(ext[1..ext.high], "")
p.add(name, readFile(file), fName & ext, contentType)
p.add(name, readFile(file).string, fName & ext, contentType)
result = p

proc `[]=`*(p: var MultipartData, name, content: string) =
Expand Down Expand Up @@ -633,7 +633,7 @@ proc parseChunks(client: HttpClient | AsyncHttpClient): Future[void]
{.multisync.} =
while true:
var chunkSize = 0
var chunkSizeStr = await client.socket.recvLine()
var chunkSizeStr = (await client.socket.recvLine()).string
var i = 0
if chunkSizeStr == "":
httpError("Server terminated connection prematurely")
Expand Down Expand Up @@ -733,9 +733,9 @@ proc parseResponse(client: HttpClient | AsyncHttpClient,
while true:
linei = 0
when client is HttpClient:
line = await client.socket.recvLine(client.timeout)
line = (await client.socket.recvLine(client.timeout)).string
else:
line = await client.socket.recvLine()
line = (await client.socket.recvLine()).string
if line == "":
# We've been disconnected.
client.close()
Expand Down
12 changes: 10 additions & 2 deletions lib/pure/streams.nim
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@

include "system/inclrtl"

const taintMode = compileOption("taintmode")

proc newEIO(msg: string): owned(ref IOError) =
new(result)
result.msg = msg
Expand Down Expand Up @@ -901,7 +903,10 @@ proc readLine*(s: Stream, line: var TaintedString): bool =
else:
# fallback
when nimvm: #Bug #12282
line.setLen(0)
when taintMode:
line.string.setLen(0)
else:
line.setLen(0)
else:
line.string.setLen(0)
while true:
Expand All @@ -914,7 +919,10 @@ proc readLine*(s: Stream, line: var TaintedString): bool =
if line.len > 0: break
else: return false
when nimvm: #Bug #12282
line.add(c)
when taintMode:
line.string.add(c)
else:
line.add(c)
else:
line.string.add(c)
result = true
Expand Down