summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2018-04-29 01:18:26 +0200
committerAndreas Rumpf <rumpf_a@web.de>2018-04-29 01:18:26 +0200
commit39b81c836cf09912296799d66124db9b1efcedc8 (patch)
treef148d574c94cc8d4f4d6f211d9d3156efe639fcd /lib
parent7e0540ed80ac0685458e1ccf9e3f7ba38772d32c (diff)
downloadNim-39b81c836cf09912296799d66124db9b1efcedc8.tar.gz
cgi module: don't depent on the terminating zero
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/cgi.nim20
1 files changed, 10 insertions, 10 deletions
diff --git a/lib/pure/cgi.nim b/lib/pure/cgi.nim
index 5de6aa487..a5a404497 100644
--- a/lib/pure/cgi.nim
+++ b/lib/pure/cgi.nim
@@ -97,11 +97,10 @@ iterator decodeData*(data: string): tuple[key, value: TaintedString] =
   var name = ""
   var value = ""
   # decode everything in one pass:
-  while data[i] != '\0':
+  while i < data.len:
     setLen(name, 0) # reuse memory
-    while true:
+    while i < data.len:
       case data[i]
-      of '\0': break
       of '%':
         var x = 0
         handleHexChar(data[i+1], x)
@@ -112,15 +111,16 @@ iterator decodeData*(data: string): tuple[key, value: TaintedString] =
       of '=', '&': break
       else: add(name, data[i])
       inc(i)
-    if data[i] != '=': cgiError("'=' expected")
+    if i >= data.len or data[i] != '=': cgiError("'=' expected")
     inc(i) # skip '='
     setLen(value, 0) # reuse memory
-    while true:
+    while i < data.len:
       case data[i]
       of '%':
         var x = 0
-        handleHexChar(data[i+1], x)
-        handleHexChar(data[i+2], x)
+        if i+2 < data.len:
+          handleHexChar(data[i+1], x)
+          handleHexChar(data[i+2], x)
         inc(i, 2)
         add(value, chr(x))
       of '+': add(value, ' ')
@@ -128,9 +128,9 @@ iterator decodeData*(data: string): tuple[key, value: TaintedString] =
       else: add(value, data[i])
       inc(i)
     yield (name.TaintedString, value.TaintedString)
-    if data[i] == '&': inc(i)
-    elif data[i] == '\0': break
-    else: cgiError("'&' expected")
+    if i < data.len:
+      if data[i] == '&': inc(i)
+      else: cgiError("'&' expected")
 
 iterator decodeData*(allowedMethods: set[RequestMethod] =
        {methodNone, methodPost, methodGet}): tuple[key, value: TaintedString] =
ght">
# create a breakpoint on `debugutils.enteringDebugSection` named enteringDebugSection
breakpoint set -n 'enteringDebugSection' -N enteringDebugSection
# run these commands once breakpoint enteringDebugSection is hit
breakpoint command add enteringDebugSection
	# enable all breakpoints
	breakpoint enable
	# enable all watchpoints
  # watchpoint enable # FIXME: not currently working for unknown reason
	# continue execution
	continue
DONE

# create a breakpoint on `debugutils.exitingDebugSection` named exitingDebugSection
breakpoint set -n 'exitingDebugSection' -N exitingDebugSection
# run these commands once breakpoint exitingDebugSection is hit
breakpoint command add exitingDebugSection
	# disable all breakpoints
	breakpoint disable
	# disable all watchpoints
  # watchpoint disable # FIXME: not currently working for unknown reason
	breakpoint enable enteringDebugSection
	# continue execution
	continue
DONE

# some commands can't be set until the process is running, so set an entry breakpoint
breakpoint set -n NimMain -N NimMain
# run these commands once breakpoint NimMain is hit
breakpoint command add NimMain
	# disable all breakpoints
	breakpoint disable
	# disable all watchpoints
  # watchpoint disable # FIXME: not currently working for unknown reason
	# enable the enteringDebugSection breakpoint though
	breakpoint enable enteringDebugSection
	# no longer need this breakpoint
	breakpoint delete NimMain
	# continue execution
	continue
DONE