Skip to content

Commit

Permalink
Fix use after free issue in inserttable() (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cito committed Mar 22, 2022
1 parent d8c2be7 commit c55d003
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions docs/contents/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
ChangeLog
=========

Version 5.2.4 (to be released)
------------------------------
- Two more fixes in the `inserttable()` method of the `pg` module:
- `inserttable()` failed to escape carriage return (#68)
- Fix use after free issue in `inserttable()` (#71)

Version 5.2.3 (2022-01-30)
--------------------------
- This version officially supports the new Python 3.10 and PostgreSQL 14.
Expand Down
6 changes: 3 additions & 3 deletions pgconn.c
Original file line number Diff line number Diff line change
Expand Up @@ -775,24 +775,24 @@ conn_inserttable(connObject *self, PyObject *args)
char *col;

if (PyBytes_Check(obj)) {
PyBytes_AsStringAndSize(obj, &col, &slen);
Py_INCREF(obj);
}
else if (PyUnicode_Check(obj)) {
obj = get_encoded_string(obj, encoding);
if (!obj) {
PyMem_Free(buffer); Py_DECREF(iter_row);
return NULL; /* pass the UnicodeEncodeError */
}
PyBytes_AsStringAndSize(obj, &col, &slen);
Py_DECREF(obj);
} else {
PyErr_SetString(
PyExc_TypeError,
"The third argument must contain only strings");
PyMem_Free(buffer); Py_DECREF(iter_row);
return NULL;
}
PyBytes_AsStringAndSize(obj, &col, &slen);
col = PQescapeIdentifier(self->cnx, col, (size_t) slen);
Py_DECREF(obj);
if (bufpt < bufmax)
bufpt += snprintf(bufpt, (size_t) (bufmax - bufpt),
"%s%s", col, j == n - 1 ? ")" : ",");
Expand Down

0 comments on commit c55d003

Please sign in to comment.