mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	bpo-31764: Prevent a crash in sqlite3.Cursor.close() in case the Cursor object is uninitialized (#3958)
This commit is contained in:
		
							parent
							
								
									e56ab746a9
								
							
						
					
					
						commit
						edb13ae48c
					
				
					 3 changed files with 10 additions and 0 deletions
				
			
		|  | @ -190,6 +190,9 @@ def __init__(self, con): | ||||||
|         cur = Cursor(con) |         cur = Cursor(con) | ||||||
|         with self.assertRaises(sqlite.ProgrammingError): |         with self.assertRaises(sqlite.ProgrammingError): | ||||||
|             cur.execute("select 4+5").fetchall() |             cur.execute("select 4+5").fetchall() | ||||||
|  |         with self.assertRaisesRegex(sqlite.ProgrammingError, | ||||||
|  |                                     r'^Base Cursor\.__init__ not called\.$'): | ||||||
|  |             cur.close() | ||||||
| 
 | 
 | ||||||
|     def CheckStrSubclass(self): |     def CheckStrSubclass(self): | ||||||
|         """ |         """ | ||||||
|  |  | ||||||
|  | @ -0,0 +1,2 @@ | ||||||
|  | Prevent a crash in ``sqlite3.Cursor.close()`` in case the ``Cursor`` object is | ||||||
|  | uninitialized. Patch by Oren Milman. | ||||||
|  | @ -889,6 +889,11 @@ PyObject* pysqlite_noop(pysqlite_Connection* self, PyObject* args) | ||||||
| 
 | 
 | ||||||
| PyObject* pysqlite_cursor_close(pysqlite_Cursor* self, PyObject* args) | PyObject* pysqlite_cursor_close(pysqlite_Cursor* self, PyObject* args) | ||||||
| { | { | ||||||
|  |     if (!self->connection) { | ||||||
|  |         PyErr_SetString(pysqlite_ProgrammingError, | ||||||
|  |                         "Base Cursor.__init__ not called."); | ||||||
|  |         return NULL; | ||||||
|  |     } | ||||||
|     if (!pysqlite_check_thread(self->connection) || !pysqlite_check_connection(self->connection)) { |     if (!pysqlite_check_thread(self->connection) || !pysqlite_check_connection(self->connection)) { | ||||||
|         return NULL; |         return NULL; | ||||||
|     } |     } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Oren Milman
						Oren Milman