mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 21:51:50 +00:00 
			
		
		
		
	#2798: PyArg_ParseTuple did not correctly handle the "s" code in case of unicode strings
with chars outside the 7bit ascii (s# was already correct). This is necessary to allow python run from a non-ASCII directory, and seems enough on some platforms, probably where the default PyUnicode encoding (utf-8) is also the default filesystem encoding.
This commit is contained in:
		
							parent
							
								
									e6161492fe
								
							
						
					
					
						commit
						0740459248
					
				
					 3 changed files with 45 additions and 8 deletions
				
			
		|  | @ -822,10 +822,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, | |||
| 			} | ||||
| 			else | ||||
| 				return converterr("string", arg, msgbuf, bufsize); | ||||
| 			/* XXX(gb): this test is completely wrong -- p is a
 | ||||
| 			 * byte string while arg is a Unicode. I *think* it should | ||||
| 			 * check against the size of uarg... */ | ||||
| 			if ((Py_ssize_t)strlen(*p) != PyUnicode_GetSize(arg)) | ||||
| 			if ((Py_ssize_t) strlen(*p) != PyString_GET_SIZE(uarg)) | ||||
| 				return converterr("string without null bytes", | ||||
| 						  arg, msgbuf, bufsize); | ||||
| 		} | ||||
|  | @ -874,11 +871,15 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, | |||
| 			format++; | ||||
| 		} else { | ||||
| 			char **p = va_arg(*p_va, char **); | ||||
| 			uarg = NULL; | ||||
| 
 | ||||
| 			if (arg == Py_None) | ||||
| 				*p = 0; | ||||
| 			else if (PyString_Check(arg)) | ||||
| 			else if (PyString_Check(arg)) { | ||||
| 				/* Enable null byte check below */ | ||||
| 				uarg = arg; | ||||
| 				*p = PyString_AS_STRING(arg); | ||||
| 			} | ||||
| 			else if (PyUnicode_Check(arg)) { | ||||
| 				uarg = UNICODE_DEFAULT_ENCODING(arg); | ||||
| 				if (uarg == NULL) | ||||
|  | @ -900,9 +901,8 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, | |||
| 				} | ||||
| 				format++; | ||||
| 			} | ||||
| 			/* XXX(gb): same comment as for 's' applies here... */ | ||||
| 			else if (*p != NULL && | ||||
| 				 (Py_ssize_t)strlen(*p) != PyUnicode_GetSize(arg)) | ||||
| 			else if (*p != NULL && uarg != NULL && | ||||
| 				(Py_ssize_t) strlen(*p) != PyString_GET_SIZE(uarg)) | ||||
| 				return converterr( | ||||
| 					"string without null bytes or None", | ||||
| 					arg, msgbuf, bufsize); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Amaury Forgeot d'Arc
						Amaury Forgeot d'Arc