[Python-checkins] CVS: python/dist/src/Python getargs.c,2.70,2.71

Tim Peters tim_one@users.sourceforge.net
Fri, 26 Oct 2001 17:46:11 -0700


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

Modified Files:
	getargs.c 
Log Message:
tuple(3,4,5,x=2) dumped core on my box.  vgetargskeywords() overindexed
the kwlist vector whenever there was a mix of positional and keyword
arguments, and the number of positional arguments exceeded the length
of the kwlist vector.  If there was just one more positional arg than
keyword, the kwlist-terminating NULL got passed to PyMapping_HasKeyString,
which set an internal error that vgetargskeywords() then squashed (but
it's impossible to say whether it knew it was masking an error).  If
more than one more positional argument, it went on to pass random trash
to PyMapping_HasKeyString, which is why the example at the start
happened to kill the process.

Pure bugfix candidate.


Index: getargs.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/getargs.c,v
retrieving revision 2.70
retrieving revision 2.71
diff -C2 -d -r2.70 -r2.71
*** getargs.c	2001/10/27 00:17:34	2.70
--- getargs.c	2001/10/27 00:46:09	2.71
***************
*** 1084,1094 ****
  	   its not clear when to use the term "keyword argument vs. 
  	   keyword parameter in messages */
! 	
  	if (keywords) {
  		for (i = 0; i < tplen; i++) {
! 			if (PyMapping_HasKeyString(keywords, kwlist[i])) {
  				sprintf(msgbuf,
  					"keyword parameter %s redefined",
! 					kwlist[i]);
  				PyErr_SetString(PyExc_TypeError, msgbuf);
  				return 0;
--- 1084,1097 ----
  	   its not clear when to use the term "keyword argument vs. 
  	   keyword parameter in messages */
! 
  	if (keywords) {
  		for (i = 0; i < tplen; i++) {
! 			char *thiskw = kwlist[i];
! 			if (thiskw == NULL)
! 				break;
! 			if (PyMapping_HasKeyString(keywords, thiskw)) {
  				sprintf(msgbuf,
  					"keyword parameter %s redefined",
! 					thiskw);
  				PyErr_SetString(PyExc_TypeError, msgbuf);
  				return 0;
***************
*** 1096,1099 ****
--- 1099,1109 ----
  		}
  	}
+ 	/* XXX The loop just above didn't used to break when hitting the
+ 	   end of kwlist, so could pass NULL on to PyMapping_HasKeyString,
+ 	   which sets a "NULL argument to internal routine" error then.
+ 	   However, the comment below doesn't give any clues about which
+ 	   'error string' it's talking about, so darned hard to say whether
+ 	   the PyErr_Clear() still serves a purpose.
+ 	*/
  	PyErr_Clear(); /* I'm not which Py functions set the error string */