mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Reported by Fredrik Lundh on python-dev. The conversimple() code that handles Unicode arguments and converts them to the default encoding now calls converterr() with the original Unicode argument instead of the NULL returned by the failed encoding attempt.
This commit is contained in:
		
							parent
							
								
									bea3fb83a7
								
							
						
					
					
						commit
						77b8b67919
					
				
					 1 changed files with 17 additions and 15 deletions
				
			
		|  | @ -368,6 +368,7 @@ static char * | |||
| converterr(char *expected, PyObject *arg, char *msgbuf) | ||||
| { | ||||
| 	assert(expected != NULL); | ||||
| 	assert(arg != NULL);  | ||||
| 	sprintf(msgbuf, "must be %.50s, not %.50s", expected, | ||||
| 		arg == Py_None ? "None" : arg->ob_type->tp_name); | ||||
| 	return msgbuf; | ||||
|  | @ -387,6 +388,7 @@ convertsimple(PyObject *arg, char **p_format, va_list *p_va, char *msgbuf) | |||
| { | ||||
| 	char *format = *p_format; | ||||
| 	char c = *format++; | ||||
| 	PyObject *uarg; | ||||
| 	 | ||||
| 	switch (c) { | ||||
| 	 | ||||
|  | @ -568,12 +570,12 @@ convertsimple(PyObject *arg, char **p_format, va_list *p_va, char *msgbuf) | |||
| 			} | ||||
| #ifdef Py_USING_UNICODE | ||||
| 			else if (PyUnicode_Check(arg)) { | ||||
| 				arg = UNICODE_DEFAULT_ENCODING(arg); | ||||
| 				if (arg == NULL) | ||||
| 				uarg = UNICODE_DEFAULT_ENCODING(arg); | ||||
| 				if (uarg == NULL) | ||||
| 					return converterr(CONV_UNICODE, | ||||
| 							  arg, msgbuf); | ||||
| 				*p = PyString_AS_STRING(arg); | ||||
| 				*q = PyString_GET_SIZE(arg); | ||||
| 				*p = PyString_AS_STRING(uarg); | ||||
| 				*q = PyString_GET_SIZE(uarg); | ||||
| 			} | ||||
| #endif | ||||
| 			else { /* any buffer-like object */ | ||||
|  | @ -591,11 +593,11 @@ convertsimple(PyObject *arg, char **p_format, va_list *p_va, char *msgbuf) | |||
| 				*p = PyString_AS_STRING(arg); | ||||
| #ifdef Py_USING_UNICODE | ||||
| 			else if (PyUnicode_Check(arg)) { | ||||
| 				arg = UNICODE_DEFAULT_ENCODING(arg); | ||||
| 				if (arg == NULL) | ||||
| 				uarg = UNICODE_DEFAULT_ENCODING(arg); | ||||
| 				if (uarg == NULL) | ||||
| 					return converterr(CONV_UNICODE, | ||||
| 							  arg, msgbuf); | ||||
| 				*p = PyString_AS_STRING(arg); | ||||
| 				*p = PyString_AS_STRING(uarg); | ||||
| 			} | ||||
| #endif | ||||
| 			else | ||||
|  | @ -622,12 +624,12 @@ convertsimple(PyObject *arg, char **p_format, va_list *p_va, char *msgbuf) | |||
| 			} | ||||
| #ifdef Py_USING_UNICODE | ||||
| 			else if (PyUnicode_Check(arg)) { | ||||
| 				arg = UNICODE_DEFAULT_ENCODING(arg); | ||||
| 				if (arg == NULL) | ||||
| 				uarg = UNICODE_DEFAULT_ENCODING(arg); | ||||
| 				if (uarg == NULL) | ||||
| 					return converterr(CONV_UNICODE, | ||||
| 							  arg, msgbuf); | ||||
| 				*p = PyString_AS_STRING(arg); | ||||
| 				*q = PyString_GET_SIZE(arg); | ||||
| 				*p = PyString_AS_STRING(uarg); | ||||
| 				*q = PyString_GET_SIZE(uarg); | ||||
| 			} | ||||
| #endif | ||||
| 			else { /* any buffer-like object */ | ||||
|  | @ -648,11 +650,11 @@ convertsimple(PyObject *arg, char **p_format, va_list *p_va, char *msgbuf) | |||
| 				*p = PyString_AsString(arg); | ||||
| #ifdef Py_USING_UNICODE | ||||
| 			else if (PyUnicode_Check(arg)) { | ||||
| 				arg = UNICODE_DEFAULT_ENCODING(arg); | ||||
| 				if (arg == NULL) | ||||
| 				uarg = UNICODE_DEFAULT_ENCODING(arg); | ||||
| 				if (uarg == NULL) | ||||
| 					return converterr(CONV_UNICODE, | ||||
| 							  arg, msgbuf); | ||||
| 				*p = PyString_AS_STRING(arg); | ||||
| 				*p = PyString_AS_STRING(uarg); | ||||
| 			} | ||||
| #endif | ||||
| 			else | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Jeremy Hylton
						Jeremy Hylton