about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-03-14 13:43:57 +0100
committerbptato <nincsnevem662@gmail.com>2024-03-14 13:43:57 +0100
commitd10d677ba4f44dbe653e0dc41d6389db69d75e2e (patch)
tree3dcc92228595a0b3fcca7d42b07b54f9b12b10b0 /src
parent781ac333e503b72d5d6070af02269164806cc597 (diff)
downloadchawan-d10d677ba4f44dbe653e0dc41d6389db69d75e2e.tar.gz
loader: fix crash on malformed CGI headers
Setting istream to nil was preventing finishCycle from unregistering &
closing it.
Diffstat (limited to 'src')
-rw-r--r--src/loader/cgi.nim3
-rw-r--r--src/loader/loader.nim2
2 files changed, 2 insertions, 3 deletions
diff --git a/src/loader/cgi.nim b/src/loader/cgi.nim
index 5bc22b6a..f7922224 100644
--- a/src/loader/cgi.nim
+++ b/src/loader/cgi.nim
@@ -238,7 +238,6 @@ proc killHandle(handle: LoaderHandle) =
     handle.sendHeaders(newHeaders())
     const msg = "Error: malformed header in CGI script"
     discard handle.output.ostream.sendData(msg)
-  handle.istream = nil
   handle.parser = nil
 
 proc parseHeaders*(handle: LoaderHandle; buffer: LoaderBuffer): int =
@@ -248,7 +247,7 @@ proc parseHeaders*(handle: LoaderHandle; buffer: LoaderBuffer): int =
   for i in 0 ..< L:
     template die =
       handle.killHandle()
-      return i
+      return -1
     let c = if buffer != nil:
       char(buffer.page[i])
     else:
diff --git a/src/loader/loader.nim b/src/loader/loader.nim
index c4b497ac..cb59a714 100644
--- a/src/loader/loader.nim
+++ b/src/loader/loader.nim
@@ -259,7 +259,7 @@ proc handleRead(ctx: LoaderContext; handle: LoaderHandle;
       var si = 0
       if handle.parser != nil:
         si = handle.parseHeaders(buffer)
-        if handle.istream == nil: # died while parsing headers; unregister
+        if si == -1: # died while parsing headers; unregister
           return hrrUnregister
         if si == n: # parsed the entire buffer as headers; skip output handling
           continue