[Python-checkins] python/dist/src/Modules socketmodule.c,1.200.6.6,1.200.6.7

loewis@users.sourceforge.net loewis@users.sourceforge.net
Sun, 28 Jul 2002 09:11:27 -0700


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

Modified Files:
      Tag: release22-maint
	socketmodule.c 
Log Message:
Pass length of result structure into setipaddr. Fixes bug #565747.


Index: socketmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/socketmodule.c,v
retrieving revision 1.200.6.6
retrieving revision 1.200.6.7
diff -C2 -d -r1.200.6.6 -r1.200.6.7
*** socketmodule.c	6 Jun 2002 20:11:15 -0000	1.200.6.6
--- socketmodule.c	28 Jul 2002 16:11:25 -0000	1.200.6.7
***************
*** 584,588 ****
  
  static int
! setipaddr(char* name, struct sockaddr * addr_ret, int af)
  {
  	struct addrinfo hints, *res;
--- 584,588 ----
  
  static int
! setipaddr(char* name, struct sockaddr * addr_ret, size_t addr_ret_size, int af)
  {
  	struct addrinfo hints, *res;
***************
*** 622,626 ****
  			return -1;
  		}
! 		memcpy(addr_ret, res->ai_addr, res->ai_addrlen);
  		freeaddrinfo(res);
  		return siz;
--- 622,628 ----
  			return -1;
  		}
! 		if (res->ai_addrlen < addr_ret_size)
! 			addr_ret_size = res->ai_addrlen;
! 		memcpy(addr_ret, res->ai_addr, addr_ret_size);
  		freeaddrinfo(res);
  		return siz;
***************
*** 657,661 ****
  		return -1;
  	}
! 	memcpy((char *) addr_ret, res->ai_addr, res->ai_addrlen);
  	freeaddrinfo(res);
  	switch (addr_ret->sa_family) {
--- 659,665 ----
  		return -1;
  	}
! 	if (res->ai_addrlen < addr_ret_size)
! 		addr_ret_size = res->ai_addrlen;
! 	memcpy((char *) addr_ret, res->ai_addr, addr_ret_size);
  	freeaddrinfo(res);
  	switch (addr_ret->sa_family) {
***************
*** 832,836 ****
  		if (!PyArg_ParseTuple(args, "si:getsockaddrarg", &host, &port))
  			return 0;
! 		if (setipaddr(host, (struct sockaddr *)addr, AF_INET) < 0)
  			return 0;
  		addr->sin_family = AF_INET;
--- 836,840 ----
  		if (!PyArg_ParseTuple(args, "si:getsockaddrarg", &host, &port))
  			return 0;
! 		if (setipaddr(host, (struct sockaddr *)addr, sizeof(*addr),  AF_INET) < 0)
  			return 0;
  		addr->sin_family = AF_INET;
***************
*** 853,857 ****
  			return 0;
  		}
! 		if (setipaddr(host, (struct sockaddr *)addr, AF_INET6) < 0)
  			return 0;
  		addr->sin6_family = s->sock_family;
--- 857,861 ----
  			return 0;
  		}
! 		if (setipaddr(host, (struct sockaddr *)addr,  sizeof(*addr), AF_INET6) < 0)
  			return 0;
  		addr->sin6_family = s->sock_family;
***************
*** 1962,1966 ****
  	if (!PyArg_ParseTuple(args, "s:gethostbyname", &name))
  		return NULL;
! 	if (setipaddr(name, (struct sockaddr *)&addrbuf, AF_INET) < 0)
  		return NULL;
  	return makeipaddr((struct sockaddr *)&addrbuf,
--- 1966,1970 ----
  	if (!PyArg_ParseTuple(args, "s:gethostbyname", &name))
  		return NULL;
! 	if (setipaddr(name, (struct sockaddr *)&addrbuf,  sizeof(addrbuf), AF_INET) < 0)
  		return NULL;
  	return makeipaddr((struct sockaddr *)&addrbuf,
***************
*** 2111,2115 ****
  	if (!PyArg_ParseTuple(args, "s:gethostbyname_ex", &name))
  		return NULL;
! 	if (setipaddr(name, (struct sockaddr *)&addr, PF_INET) < 0)
  		return NULL;
  	Py_BEGIN_ALLOW_THREADS
--- 2115,2119 ----
  	if (!PyArg_ParseTuple(args, "s:gethostbyname_ex", &name))
  		return NULL;
! 	if (setipaddr(name, (struct sockaddr *)&addr, sizeof(addr), PF_INET) < 0)
  		return NULL;
  	Py_BEGIN_ALLOW_THREADS
***************
*** 2183,2187 ****
  		return NULL;
  	af = PF_UNSPEC;
! 	if (setipaddr(ip_num, sa, af) < 0)
  		return NULL;
  	af = sa->sa_family;
--- 2187,2191 ----
  		return NULL;
  	af = PF_UNSPEC;
! 	if (setipaddr(ip_num, sa, sizeof(addr), af) < 0)
  		return NULL;
  	af = sa->sa_family;