[Python-checkins] CVS: python/dist/src/Modules socketmodule.c,1.141,1.142

Fred L. Drake fdrake@users.sourceforge.net
Wed, 09 May 2001 12:11:35 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv30687/Modules

Modified Files:
	socketmodule.c 
Log Message:

Three uses of makesockaddr() used sockaddr buffers that had not be cleared;
this could cause invalid paths to be returned for AF_UNIX sockets on some
platforms (including FreeBSD 4.2-RELEASE), appearantly because there is
no assurance that the address will be nul-terminated when filled in by the
kernel.

PySocketSock_recvfrom():  Use PyString_AS_STRING() to get the data pointer
    of a string we create ourselves; there is no need for the extra type
    check from PyString_AsString().

This closes SF bug #416573.


Index: socketmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/socketmodule.c,v
retrieving revision 1.141
retrieving revision 1.142
diff -C2 -r1.141 -r1.142
*** socketmodule.c	2001/04/16 00:21:33	1.141
--- socketmodule.c	2001/05/09 19:11:33	1.142
***************
*** 791,794 ****
--- 791,795 ----
  	if (!getsockaddrlen(s, &addrlen))
  		return NULL;
+ 	memset(addrbuf, 0, addrlen);
  	Py_BEGIN_ALLOW_THREADS
  	newfd = accept(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen);
***************
*** 1213,1216 ****
--- 1214,1218 ----
  	if (!getsockaddrlen(s, &addrlen))
  		return NULL;
+ 	memset(addrbuf, 0, addrlen);
  	Py_BEGIN_ALLOW_THREADS
  	res = getpeername(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen);
***************
*** 1361,1365 ****
  		return NULL;
  	Py_BEGIN_ALLOW_THREADS
! 	n = recvfrom(s->sock_fd, PyString_AsString(buf), len, flags,
  #ifndef MS_WINDOWS
  #if defined(PYOS_OS2)
--- 1363,1368 ----
  		return NULL;
  	Py_BEGIN_ALLOW_THREADS
! 	memset(addrbuf, 0, addrlen);
! 	n = recvfrom(s->sock_fd, PyString_AS_STRING(buf), len, flags,
  #ifndef MS_WINDOWS
  #if defined(PYOS_OS2)