Skip to content

Commit 4644715

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 5b28d7b commit 4644715

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
@@ -1081,7 +1081,16 @@ conn_poll(connectionObject *self)
10811081
/* An async query has just finished: parse the tuple in the
10821082
* target cursor. */
10831083
cursorObject *curs;
1084-
PyObject *py_curs = PyWeakref_GetObject(self->async_cursor);
1084+
PyObject *py_curs;
1085+
if (!(py_curs = PyWeakref_GetObject(self->async_cursor))) {
1086+
/* It shouldn't happen but consider it to avoid dereferencing
1087+
* a null pointer below. */
1088+
pq_clear_async(self);
1089+
PyErr_SetString(PyExc_SystemError,
1090+
"got null dereferencing cursor weakref");
1091+
res = PSYCO_POLL_ERROR;
1092+
break;
1093+
}
10851094
if (Py_None == py_curs) {
10861095
pq_clear_async(self);
10871096
PyErr_SetString(InterfaceError,

0 commit comments

Comments
 (0)