summaryrefslogtreecommitdiffstats
path: root/Lib/cgi.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-10-23 10:54:42 (GMT)
committerGitHub <noreply@github.com>2018-10-23 10:54:42 (GMT)
commit58b614a327991f4baad4d2795a50027f75411450 (patch)
tree67102a8802e90af055d1bab6b1eb693462228d14 /Lib/cgi.py
parent42892a2a38bb97c41e7b1b154e2b5b6f13d27b57 (diff)
downloadcpython-58b614a327991f4baad4d2795a50027f75411450.zip
cpython-58b614a327991f4baad4d2795a50027f75411450.tar.gz
cpython-58b614a327991f4baad4d2795a50027f75411450.tar.bz2
bpo-35028: cgi: Fix max_num_fields off by one error (GH-9973)
https://bugs.python.org/issue35028 (cherry picked from commit b79b5c09493e98374e48fa122d82dab528fc6e72) Co-authored-by: matthewbelisle-wf <matthew.belisle@workiva.com>
Diffstat (limited to 'Lib/cgi.py')
-rwxr-xr-xLib/cgi.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/Lib/cgi.py b/Lib/cgi.py
index 2407707..56f243e 100755
--- a/Lib/cgi.py
+++ b/Lib/cgi.py
@@ -710,6 +710,11 @@ class FieldStorage:
first_line = self.fp.readline()
self.bytes_read += len(first_line)
+ # Propagate max_num_fields into the sub class appropriately
+ max_num_fields = self.max_num_fields
+ if max_num_fields is not None:
+ max_num_fields -= len(self.list)
+
while True:
parser = FeedParser()
hdr_text = b""
@@ -729,23 +734,19 @@ class FieldStorage:
if 'content-length' in headers:
del headers['content-length']
- # Propagate max_num_fields into the sub class appropriately
- sub_max_num_fields = self.max_num_fields
- if sub_max_num_fields is not None:
- sub_max_num_fields -= len(self.list)
-
part = klass(self.fp, headers, ib, environ, keep_blank_values,
strict_parsing,self.limit-self.bytes_read,
- self.encoding, self.errors, sub_max_num_fields)
+ self.encoding, self.errors, max_num_fields)
- max_num_fields = self.max_num_fields
- if max_num_fields is not None and part.list:
- max_num_fields -= len(part.list)
+ if max_num_fields is not None:
+ max_num_fields -= 1
+ if part.list:
+ max_num_fields -= len(part.list)
+ if max_num_fields < 0:
+ raise ValueError('Max number of fields exceeded')
self.bytes_read += part.bytes_read
self.list.append(part)
- if max_num_fields is not None and max_num_fields < len(self.list):
- raise ValueError('Max number of fields exceeded')
if part.done or self.bytes_read >= self.length > 0:
break
self.skip_lines()