mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-21 14:55:24 +00:00
Added fix for handling TaintedStrings in streams and httpclient (#12969)
* Added fix for taint mode in streams and httpclient * Removed taintMode export from system.nim
This commit is contained in:
@@ -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) =
|
||||
@@ -634,7 +634,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")
|
||||
@@ -734,9 +734,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()
|
||||
|
||||
@@ -96,6 +96,8 @@
|
||||
|
||||
include "system/inclrtl"
|
||||
|
||||
const taintMode = compileOption("taintmode")
|
||||
|
||||
proc newEIO(msg: string): owned(ref IOError) =
|
||||
new(result)
|
||||
result.msg = msg
|
||||
@@ -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:
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user