[Patches] [ python-Patches-410046 ] asynchat: handle excessive response size
noreply@sourceforge.net
noreply@sourceforge.net
Tue, 20 Mar 2001 08:36:38 -0800
Patches item #410046, was updated on 2001-03-20 08:32
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=410046&group_id=5470
Category: library
Group: None
Status: Open
Priority: 5
Submitted By: Doug Fort (dougfort)
Assigned to: Nobody/Anonymous (nobody)
Summary: asynchat: handle excessive response size
Initial Comment:
When reading with a numeric terminator, asynchat assumes that if the server didn't send fewer bytes than requested, that it sent exactly the number of bytes requested. This is normally the case, but an overloaded server can return an error message that is larger than the number of bytes requested. When this happens asynchttp.handle_read() goes into a tight loop, returning an empty string for data and zero for a terminator.
This patch raises an exception if the number of bytes returned exceeds the number requested. It's kind of an ugly fix, because asynchttp doesn't raise any other exceptions, and passes on those it catches to handle_error. However, this really is an exceptional case, and the results of not handling it are disastrous.
----------------------------------------------------------------------
>Comment By: Doug Fort (dougfort)
Date: 2001-03-20 08:36
Message:
Logged In: YES
user_id=6399
*** asynchat.pyTue Mar 20 11:11:58 2001
--- asynchat.py.originalTue Mar 20 10:43:01 2001
***************
*** 49,60 ****
import socket
import asyncore
- class async_chat_exception(Exception):
- def __init__(self, message):
- self._message = message
- def __str__(self):
- return self._message
-
class async_chat (asyncore.dispatcher):
"""This is an abstract class. You must derive from this class, and add
the two methods collect_incoming_data() and found_terminator()"""
--- 49,54 ----
***************
*** 111,128 ****
self.collect_incoming_data (self.ac_in_buffer)
self.ac_in_buffer = ''
self.terminator = self.terminator - lb
! elif lb == n:
self.collect_incoming_data (self.ac_in_buffer[:n])
! self.ac_in_buffer = ''
self.terminator = 0
self.found_terminator()
- else:
- # if we got back more than we asked for, the server
- # is badly confused
- raise async_chat_exception(
- "Unexpect response: requested %s bytes got %s. %s" % (
- n, lb, self.ac_in_buffer
- ))
else:
# 3 cases:
# 1) end of buffer matches terminator exactly:
--- 105,115 ----
self.collect_incoming_data (self.ac_in_buffer)
self.ac_in_buffer = ''
self.terminator = self.terminator - lb
! else:
self.collect_incoming_data (self.ac_in_buffer[:n])
! self.ac_in_buffer = self.ac_in_buffer[n:]
self.terminator = 0
self.found_terminator()
else:
# 3 cases:
# 1) end of buffer matches terminator exactly:
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=410046&group_id=5470