Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
c7fd523a
Commit
c7fd523a
authored
13 years ago
by
Petri Lehtinen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
parent
cec6a61d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
10 deletions
+45
-10
Lib/sqlite3/test/regression.py
Lib/sqlite3/test/regression.py
+22
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/_sqlite/cursor.c
Modules/_sqlite/cursor.c
+19
-10
Modules/_sqlite/cursor.h
Modules/_sqlite/cursor.h
+1
-0
No files found.
Lib/sqlite3/test/regression.py
View file @
c7fd523a
...
...
@@ -264,6 +264,28 @@ class RegressionTests(unittest.TestCase):
"""
self
.
assertRaises
(
sqlite
.
Warning
,
self
.
con
,
1
)
def
CheckRecursiveCursorUse
(
self
):
"""
http://bugs.python.org/issue10811
Recursively using a cursor, such as when reusing it from a generator led to segfaults.
Now we catch recursive cursor usage and raise a ProgrammingError.
"""
con
=
sqlite
.
connect
(
":memory:"
)
cur
=
con
.
cursor
()
cur
.
execute
(
"create table a (bar)"
)
cur
.
execute
(
"create table b (baz)"
)
def
foo
():
cur
.
execute
(
"insert into a (bar) values (?)"
,
(
1
,))
yield
1
with
self
.
assertRaises
(
sqlite
.
ProgrammingError
):
cur
.
executemany
(
"insert into b (baz) values (?)"
,
((
i
,)
for
i
in
foo
()))
def
suite
():
regression_suite
=
unittest
.
makeSuite
(
RegressionTests
,
"Check"
)
return
unittest
.
TestSuite
((
regression_suite
,))
...
...
This diff is collapsed.
Click to expand it.
Misc/NEWS
View file @
c7fd523a
...
...
@@ -90,6 +90,9 @@ Core and Builtins
Library
-------
- Issue #10811: Fix recursive usage of cursors. Instead of crashing,
raise a ProgrammingError now.
- Issue #10881: Fix test_site failures with OS X framework builds.
- Issue #964437 Make IDLE help window non-modal.
...
...
This diff is collapsed.
Click to expand it.
Modules/_sqlite/cursor.c
View file @
c7fd523a
...
...
@@ -443,9 +443,14 @@ static int check_cursor(pysqlite_Cursor* cur)
if
(
cur
->
closed
)
{
PyErr_SetString
(
pysqlite_ProgrammingError
,
"Cannot operate on a closed cursor."
);
return
0
;
}
else
{
return
pysqlite_check_thread
(
cur
->
connection
)
&&
pysqlite_check_connection
(
cur
->
connection
);
}
if
(
cur
->
locked
)
{
PyErr_SetString
(
pysqlite_ProgrammingError
,
"Recursive use of cursors not allowed."
);
return
0
;
}
return
pysqlite_check_thread
(
cur
->
connection
)
&&
pysqlite_check_connection
(
cur
->
connection
);
}
PyObject
*
_pysqlite_query_execute
(
pysqlite_Cursor
*
self
,
int
multiple
,
PyObject
*
args
)
...
...
@@ -468,9 +473,10 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
int
allow_8bit_chars
;
if
(
!
check_cursor
(
self
))
{
return
NULL
;
goto
error
;
}
self
->
locked
=
1
;
self
->
reset
=
0
;
/* Make shooting yourself in the foot with not utf-8 decodable 8-bit-strings harder */
...
...
@@ -483,12 +489,12 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
if
(
multiple
)
{
/* executemany() */
if
(
!
PyArg_ParseTuple
(
args
,
"OO"
,
&
operation
,
&
second_argument
))
{
return
NULL
;
goto
error
;
}
if
(
!
PyString_Check
(
operation
)
&&
!
PyUnicode_Check
(
operation
))
{
PyErr_SetString
(
PyExc_ValueError
,
"operation parameter must be str or unicode"
);
return
NULL
;
goto
error
;
}
if
(
PyIter_Check
(
second_argument
))
{
...
...
@@ -499,23 +505,23 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
/* sequence */
parameters_iter
=
PyObject_GetIter
(
second_argument
);
if
(
!
parameters_iter
)
{
return
NULL
;
goto
error
;
}
}
}
else
{
/* execute() */
if
(
!
PyArg_ParseTuple
(
args
,
"O|O"
,
&
operation
,
&
second_argument
))
{
return
NULL
;
goto
error
;
}
if
(
!
PyString_Check
(
operation
)
&&
!
PyUnicode_Check
(
operation
))
{
PyErr_SetString
(
PyExc_ValueError
,
"operation parameter must be str or unicode"
);
return
NULL
;
goto
error
;
}
parameters_list
=
PyList_New
(
0
);
if
(
!
parameters_list
)
{
return
NULL
;
goto
error
;
}
if
(
second_argument
==
NULL
)
{
...
...
@@ -761,7 +767,8 @@ error:
* ROLLBACK could have happened */
#ifdef SQLITE_VERSION_NUMBER
#if SQLITE_VERSION_NUMBER >= 3002002
self
->
connection
->
inTransaction
=
!
sqlite3_get_autocommit
(
self
->
connection
->
db
);
if
(
self
->
connection
&&
self
->
connection
->
db
)
self
->
connection
->
inTransaction
=
!
sqlite3_get_autocommit
(
self
->
connection
->
db
);
#endif
#endif
...
...
@@ -770,6 +777,8 @@ error:
Py_XDECREF
(
parameters_iter
);
Py_XDECREF
(
parameters_list
);
self
->
locked
=
0
;
if
(
PyErr_Occurred
())
{
self
->
rowcount
=
-
1L
;
return
NULL
;
...
...
This diff is collapsed.
Click to expand it.
Modules/_sqlite/cursor.h
View file @
c7fd523a
...
...
@@ -42,6 +42,7 @@ typedef struct
pysqlite_Statement
*
statement
;
int
closed
;
int
reset
;
int
locked
;
int
initialized
;
/* the next row to be returned, NULL if no next row available */
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment