mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-29 04:13:43 +03:00
Fixed use of Python object with refcount 0 in cursor_init
Caused segfault running test_cursor.CursorTests.test_invalid_name under Python 3.4 built in debug mode.
This commit is contained in:
parent
81443c3a65
commit
ca98167ae4
1
NEWS
1
NEWS
|
@ -25,6 +25,7 @@ What's new in psycopg 2.5.3
|
||||||
(:ticket:`#203`).
|
(:ticket:`#203`).
|
||||||
- Don't segfault using poorly defined cursor subclasses which forgot to call
|
- Don't segfault using poorly defined cursor subclasses which forgot to call
|
||||||
the superclass init (:ticket:`#195`).
|
the superclass init (:ticket:`#195`).
|
||||||
|
- Fixed possible segfault in named cursors creation.
|
||||||
- Fixed debug build on Windows, thanks to James Emerton.
|
- Fixed debug build on Windows, thanks to James Emerton.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1899,31 +1899,34 @@ cursor_init(PyObject *obj, PyObject *args, PyObject *kwargs)
|
||||||
{
|
{
|
||||||
PyObject *conn;
|
PyObject *conn;
|
||||||
PyObject *name = Py_None;
|
PyObject *name = Py_None;
|
||||||
const char *cname;
|
PyObject *bname = NULL;
|
||||||
|
const char *cname = NULL;
|
||||||
|
int rv = -1;
|
||||||
|
|
||||||
static char *kwlist[] = {"conn", "name", NULL};
|
static char *kwlist[] = {"conn", "name", NULL};
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!|O", kwlist,
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!|O", kwlist,
|
||||||
&connectionType, &conn, &name)) {
|
&connectionType, &conn, &name)) {
|
||||||
return -1;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name == Py_None) {
|
if (name != Py_None) {
|
||||||
cname = NULL;
|
|
||||||
} else {
|
|
||||||
Py_INCREF(name); /* for ensure_bytes */
|
Py_INCREF(name); /* for ensure_bytes */
|
||||||
if (!(name = psycopg_ensure_bytes(name))) {
|
if (!(bname = psycopg_ensure_bytes(name))) {
|
||||||
/* name has had a ref stolen */
|
/* name has had a ref stolen */
|
||||||
return -1;
|
goto exit;
|
||||||
}
|
}
|
||||||
Py_DECREF(name);
|
|
||||||
|
|
||||||
if (!(cname = Bytes_AsString(name))) {
|
if (!(cname = Bytes_AsString(bname))) {
|
||||||
return -1;
|
goto exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cursor_setup((cursorObject *)obj, (connectionObject *)conn, cname);
|
rv = cursor_setup((cursorObject *)obj, (connectionObject *)conn, cname);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
Py_XDECREF(bname);
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
Loading…
Reference in New Issue
Block a user