Skip to content

Commit b515e0f

Browse files
committed
Consider the case dereferencing weakref in conn_poll returns NULL
It shouldn't but handle the case to avoid a possible null pointer dereferencing.
1 parent a97d132 commit b515e0f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

psycopg/connection_int.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,16 @@ conn_poll(connectionObject *self)
10821082
/* An async query has just finished: parse the tuple in the
10831083
* target cursor. */
10841084
cursorObject *curs;
1085-
PyObject *py_curs = PyWeakref_GetObject(self->async_cursor);
1085+
PyObject *py_curs;
1086+
if (!(py_curs = PyWeakref_GetObject(self->async_cursor))) {
1087+
/* It shouldn't happen but consider it to avoid dereferencing
1088+
* a null pointer below. */
1089+
pq_clear_async(self);
1090+
PyErr_SetString(PyExc_SystemError,
1091+
"got null dereferencing cursor weakref");
1092+
res = PSYCO_POLL_ERROR;
1093+
break;
1094+
}
10861095
if (Py_None == py_curs) {
10871096
pq_clear_async(self);
10881097
PyErr_SetString(InterfaceError,

0 commit comments

Comments
 (0)