diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2018-12-28 14:28:29 +0100 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2019-01-21 02:41:58 +0000 |
commit | 46447151647dfd68002ca4e1621e800adc6ffd6f (patch) | |
tree | 9c059f7ceee39d4968ea7dd094c2222825b45839 /psycopg | |
parent | 5b28d7b9c9bca78bcd8b46bfea94dd2e209ec1f4 (diff) | |
download | psycopg2-46447151647dfd68002ca4e1621e800adc6ffd6f.tar.gz |
Consider the case dereferencing weakref in conn_poll returns NULL
It shouldn't but handle the case to avoid a possible null pointer
dereferencing.
Diffstat (limited to 'psycopg')
-rw-r--r-- | psycopg/connection_int.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c index 7f6b755..17509cf 100644 --- a/psycopg/connection_int.c +++ b/psycopg/connection_int.c @@ -1081,7 +1081,16 @@ conn_poll(connectionObject *self) /* An async query has just finished: parse the tuple in the * target cursor. */ cursorObject *curs; - PyObject *py_curs = PyWeakref_GetObject(self->async_cursor); + PyObject *py_curs; + if (!(py_curs = PyWeakref_GetObject(self->async_cursor))) { + /* It shouldn't happen but consider it to avoid dereferencing + * a null pointer below. */ + pq_clear_async(self); + PyErr_SetString(PyExc_SystemError, + "got null dereferencing cursor weakref"); + res = PSYCO_POLL_ERROR; + break; + } if (Py_None == py_curs) { pq_clear_async(self); PyErr_SetString(InterfaceError, |