a99c0c697c
fixes taken from the Python 2.7 branch in the Python SVN repository.
104 lines
3.4 KiB
Text
104 lines
3.4 KiB
Text
$NetBSD: patch-ba,v 1.1 2010/11/23 08:24:04 tron Exp $
|
|
|
|
Fix for CVE-2010-3492, taken from the Python SVN repository:
|
|
|
|
http://svn.python.org/view?view=rev&revision=86084
|
|
|
|
--- Doc/library/asyncore.rst.orig 2010-05-19 15:14:45.000000000 +0100
|
|
+++ Doc/library/asyncore.rst 2010-11-22 18:11:58.000000000 +0000
|
|
@@ -211,10 +211,13 @@
|
|
.. method:: accept()
|
|
|
|
Accept a connection. The socket must be bound to an address and listening
|
|
- for connections. The return value is a pair ``(conn, address)`` where
|
|
- *conn* is a *new* socket object usable to send and receive data on the
|
|
- connection, and *address* is the address bound to the socket on the other
|
|
- end of the connection.
|
|
+ for connections. The return value can be either ``None`` or a pair
|
|
+ ``(conn, address)`` where *conn* is a *new* socket object usable to send
|
|
+ and receive data on the connection, and *address* is the address bound to
|
|
+ the socket on the other end of the connection.
|
|
+ When ``None`` is returned it means the connection didn't take place, in
|
|
+ which case the server should just ignore this event and keep listening
|
|
+ for further incoming connections.
|
|
|
|
|
|
.. method:: close()
|
|
@@ -224,6 +227,12 @@
|
|
flushed). Sockets are automatically closed when they are
|
|
garbage-collected.
|
|
|
|
+.. class:: dispatcher_with_send()
|
|
+
|
|
+ A :class:`dispatcher` subclass which adds simple buffered output capability,
|
|
+ useful for simple clients. For more sophisticated usage use
|
|
+ :class:`asynchat.async_chat`.
|
|
+
|
|
.. class:: file_dispatcher()
|
|
|
|
A file_dispatcher takes a file descriptor or file object along with an
|
|
@@ -240,7 +249,7 @@
|
|
socket for use by the :class:`file_dispatcher` class. Availability: UNIX.
|
|
|
|
|
|
-.. _asyncore-example:
|
|
+.. _asyncore-example-1:
|
|
|
|
asyncore Example basic HTTP client
|
|
----------------------------------
|
|
@@ -250,7 +259,7 @@
|
|
|
|
import asyncore, socket
|
|
|
|
- class http_client(asyncore.dispatcher):
|
|
+ class HTTPClient(asyncore.dispatcher):
|
|
|
|
def __init__(self, host, path):
|
|
asyncore.dispatcher.__init__(self)
|
|
@@ -274,6 +283,45 @@
|
|
sent = self.send(self.buffer)
|
|
self.buffer = self.buffer[sent:]
|
|
|
|
- c = http_client('www.python.org', '/')
|
|
|
|
+ client = HTTPClient('www.python.org', '/')
|
|
asyncore.loop()
|
|
+
|
|
+.. _asyncore-example-2:
|
|
+
|
|
+asyncore Example basic echo server
|
|
+----------------------------------
|
|
+
|
|
+Here is abasic echo server that uses the :class:`dispatcher` class to accept
|
|
+connections and dispatches the incoming connections to a handler::
|
|
+
|
|
+ import asyncore
|
|
+ import socket
|
|
+
|
|
+ class EchoHandler(asyncore.dispatcher_with_send):
|
|
+
|
|
+ def handle_read(self):
|
|
+ data = self.recv(8192)
|
|
+ self.send(data)
|
|
+
|
|
+ class EchoServer(asyncore.dispatcher):
|
|
+
|
|
+ def __init__(self, host, port):
|
|
+ asyncore.dispatcher.__init__(self)
|
|
+ self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
+ self.set_reuse_addr()
|
|
+ self.bind((host, port))
|
|
+ self.listen(5)
|
|
+
|
|
+ def handle_accept(self):
|
|
+ pair = self.accept()
|
|
+ if pair is None:
|
|
+ pass
|
|
+ else:
|
|
+ sock, addr = pair
|
|
+ print 'Incoming connection from %s' % repr(addr)
|
|
+ handler = EchoHandler(sock)
|
|
+
|
|
+ server = EchoServer('localhost', 8080)
|
|
+ asyncore.loop()
|
|
+
|