[Patches] [ python-Patches-405845 ] Fix for #405427: raise BadStatusLine

nobody nobody@sourceforge.net
Sun, 04 Mar 2001 08:59:18 -0800


Patches #405845, was updated on 2001-03-04 08:57
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=405845&group_id=5470

Category: Modules
Group: None
Status: Open
Priority: 5
Submitted By: Martin v. Löwis
Assigned to: Jeremy Hylton
Summary: Fix for #405427: raise BadStatusLine

Initial Comment:
If the status code is not well-formatted, this patch
raises a BadStatusLine exception

----------------------------------------------------------------------

Comment By: Martin v. Löwis
Date: 2001-03-04 08:59

Message:
Logged In: YES 
user_id=21627

Since patch upload still does not work, I attach it inline

Index: httplib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/httplib.py,v
retrieving revision 1.33
diff -u -r1.33 httplib.py
--- httplib.py	2001/02/01 23:35:20	1.33
+++ httplib.py	2001/03/04 16:52:34
@@ -126,7 +126,15 @@
             self.close()
             raise BadStatusLine(line)
 
-        self.status = status = int(status)
+        # The status code is a three-digit number
+        if len(status) != 3:
+            raise BadStatusLine(line)
+        try:
+            self.status = status = int(status)
+            if status < 100:
+                raise BadStatusLine(line)
+        except ValueError:
+            raise BadStatusLine(line)
         self.reason = reason.strip()
 
         if version == 'HTTP/1.0':
--- /dev/null	Fri Dec 22 00:32:13 2000
+++ test/test_httplib.py	Sun Mar  4 17:53:00 2001
@@ -0,0 +1,31 @@
+from test.test_support import verify,verbose
+import httplib
+import StringIO
+
+class FakeSocket:
+    def __init__(self, text):
+        self.text = text
+
+    def makefile(self, mode, bufsize=None):
+        if mode != 'r' and mode != 'rb':
+            raise UnimplementedFileMode()
+        return StringIO.StringIO(self.text)
+
+# Test HTTP status lines
+
+body = "HTTP/1.1 200 Ok\r\n\r\nText"
+sock = FakeSocket(body)
+resp = httplib.HTTPResponse(sock,1)
+resp.begin()
+print resp.read()
+resp.close()
+
+body = "HTTP/1.1 400.100 Not Ok\r\n\r\nText"
+sock = FakeSocket(body)
+resp = httplib.HTTPResponse(sock,1)
+try:
+    resp.begin()
+except httplib.BadStatusLine:
+    print "PASS"
+else:
+    print "FAIL"


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=405845&group_id=5470