mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 21:51:50 +00:00 
			
		
		
		
	gh-107913: Fix possible losses of OSError error codes (GH-107930)
Functions like PyErr_SetFromErrno() and SetFromWindowsErr() should be called immediately after using the C API which sets errno or the Windows error code.
This commit is contained in:
		
							parent
							
								
									e407cea193
								
							
						
					
					
						commit
						2b15536fa9
					
				
					 17 changed files with 129 additions and 75 deletions
				
			
		|  | @ -1790,6 +1790,7 @@ _Py_fopen_obj(PyObject *path, const char *mode) | |||
|         Py_END_ALLOW_THREADS | ||||
|     } while (f == NULL | ||||
|              && errno == EINTR && !(async_err = PyErr_CheckSignals())); | ||||
|     int saved_errno = errno; | ||||
|     PyMem_Free(wpath); | ||||
| #else | ||||
|     PyObject *bytes; | ||||
|  | @ -1812,13 +1813,14 @@ _Py_fopen_obj(PyObject *path, const char *mode) | |||
|         Py_END_ALLOW_THREADS | ||||
|     } while (f == NULL | ||||
|              && errno == EINTR && !(async_err = PyErr_CheckSignals())); | ||||
| 
 | ||||
|     int saved_errno = errno; | ||||
|     Py_DECREF(bytes); | ||||
| #endif | ||||
|     if (async_err) | ||||
|         return NULL; | ||||
| 
 | ||||
|     if (f == NULL) { | ||||
|         errno = saved_errno; | ||||
|         PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, path); | ||||
|         return NULL; | ||||
|     } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Serhiy Storchaka
						Serhiy Storchaka