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
ef113cd4
Commit
ef113cd4
authored
Aug 29, 2016
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #27861: Fixed a crash in sqlite3.Connection.cursor() when a factory
creates not a cursor. Patch by Xiang Zhang.
parent
5de141f1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
9 deletions
+35
-9
Doc/library/sqlite3.rst
Doc/library/sqlite3.rst
+4
-4
Lib/sqlite3/test/factory.py
Lib/sqlite3/test/factory.py
+17
-3
Misc/NEWS
Misc/NEWS
+3
-0
Modules/_sqlite/connection.c
Modules/_sqlite/connection.c
+11
-2
No files found.
Doc/library/sqlite3.rst
View file @
ef113cd4
...
...
@@ -285,11 +285,11 @@ Connection Objects
.. versionadded:: 3.2
.. method:: cursor(
[cursorClass]
)
.. method:: cursor(
factory=Cursor
)
The cursor method accepts a single optional parameter *
cursorClass
*. If
supplied, this must be a c
ustom cursor class that extends
:class:`sqlite3.Cursor`
.
The cursor method accepts a single optional parameter *
factory
*. If
supplied, this must be a c
allable returning an instance of :class:`Cursor`
or its subclasses
.
.. method:: commit()
...
...
Lib/sqlite3/test/factory.py
View file @
ef113cd4
...
...
@@ -58,9 +58,21 @@ class CursorFactoryTests(unittest.TestCase):
self
.
con
.
close
()
def
CheckIsInstance
(
self
):
cur
=
self
.
con
.
cursor
(
factory
=
MyCursor
)
cur
=
self
.
con
.
cursor
()
self
.
assertIsInstance
(
cur
,
sqlite
.
Cursor
)
cur
=
self
.
con
.
cursor
(
MyCursor
)
self
.
assertIsInstance
(
cur
,
MyCursor
)
cur
=
self
.
con
.
cursor
(
factory
=
lambda
con
:
MyCursor
(
con
))
self
.
assertIsInstance
(
cur
,
MyCursor
)
def
CheckInvalidFactory
(
self
):
# not a callable at all
self
.
assertRaises
(
TypeError
,
self
.
con
.
cursor
,
None
)
# invalid callable with not exact one argument
self
.
assertRaises
(
TypeError
,
self
.
con
.
cursor
,
lambda
:
None
)
# invalid callable returning non-cursor
self
.
assertRaises
(
TypeError
,
self
.
con
.
cursor
,
lambda
con
:
None
)
class
RowFactoryTestsBackwardsCompat
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
con
=
sqlite
.
connect
(
":memory:"
)
...
...
@@ -183,10 +195,12 @@ class RowFactoryTests(unittest.TestCase):
def
CheckFakeCursorClass
(
self
):
# Issue #24257: Incorrect use of PyObject_IsInstance() caused
# segmentation fault.
# Issue #27861: Also applies for cursor factory.
class
FakeCursor
(
str
):
__class__
=
sqlite
.
Cursor
cur
=
self
.
con
.
cursor
(
factory
=
FakeCursor
)
self
.
assertRaises
(
TypeError
,
sqlite
.
Row
,
cur
,
())
self
.
con
.
row_factory
=
sqlite
.
Row
self
.
assertRaises
(
TypeError
,
self
.
con
.
cursor
,
FakeCursor
)
self
.
assertRaises
(
TypeError
,
sqlite
.
Row
,
FakeCursor
(),
())
def
tearDown
(
self
):
self
.
con
.
close
()
...
...
Misc/NEWS
View file @
ef113cd4
...
...
@@ -50,6 +50,9 @@ Core and Builtins
Library
-------
-
Issue
#
27861
:
Fixed
a
crash
in
sqlite3
.
Connection
.
cursor
()
when
a
factory
creates
not
a
cursor
.
Patch
by
Xiang
Zhang
.
-
Issue
#
19884
:
Avoid
spurious
output
on
OS
X
with
Gnu
Readline
.
-
Issue
#
10513
:
Fix
a
regression
in
Connection
.
commit
().
Statements
should
...
...
Modules/_sqlite/connection.c
View file @
ef113cd4
...
...
@@ -300,7 +300,7 @@ error:
PyObject
*
pysqlite_connection_cursor
(
pysqlite_Connection
*
self
,
PyObject
*
args
,
PyObject
*
kwargs
)
{
static
char
*
kwlist
[]
=
{
"factory"
,
NULL
,
NULL
};
static
char
*
kwlist
[]
=
{
"factory"
,
NULL
};
PyObject
*
factory
=
NULL
;
PyObject
*
cursor
;
...
...
@@ -317,7 +317,16 @@ PyObject* pysqlite_connection_cursor(pysqlite_Connection* self, PyObject* args,
factory
=
(
PyObject
*
)
&
pysqlite_CursorType
;
}
cursor
=
PyObject_CallFunction
(
factory
,
"O"
,
self
);
cursor
=
PyObject_CallFunctionObjArgs
(
factory
,
(
PyObject
*
)
self
,
NULL
);
if
(
cursor
==
NULL
)
return
NULL
;
if
(
!
PyObject_TypeCheck
(
cursor
,
&
pysqlite_CursorType
))
{
PyErr_Format
(
PyExc_TypeError
,
"factory must return a cursor, not %.100s"
,
Py_TYPE
(
cursor
)
->
tp_name
);
Py_DECREF
(
cursor
);
return
NULL
;
}
_pysqlite_drop_unused_cursor_references
(
self
);
...
...
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