summaryrefslogtreecommitdiff
path: root/psycopg/pqpath.c
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2014-06-06 21:21:39 +0200
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2014-06-06 21:42:21 +0200
commit56adc590fffbc76fa5e99aa64c657621a630cbe1 (patch)
treec4f869bde32787cf20c3edcf7e03f470a1675af0 /psycopg/pqpath.c
parent115ceea1eb894b23dfbfe92cf7479ddf47f6de1b (diff)
downloadpsycopg2-56adc590fffbc76fa5e99aa64c657621a630cbe1.tar.gz
Fixed segfault if COPY statements are executed
Close ticket #219
Diffstat (limited to 'psycopg/pqpath.c')
-rw-r--r--psycopg/pqpath.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c
index 05d22ee..42460f5 100644
--- a/psycopg/pqpath.c
+++ b/psycopg/pqpath.c
@@ -1288,6 +1288,13 @@ _pq_copy_in_v3(cursorObject *curs)
Py_ssize_t length = 0;
int res, error = 0;
+ if (!curs->copyfile) {
+ PyErr_SetString(ProgrammingError,
+ "can't execute COPY FROM: use the copy_from() method instead");
+ error = 1;
+ goto exit;
+ }
+
if (!(func = PyObject_GetAttrString(curs->copyfile, "read"))) {
Dprintf("_pq_copy_in_v3: can't get o.read");
error = 1;
@@ -1411,7 +1418,8 @@ exit:
static int
_pq_copy_out_v3(cursorObject *curs)
{
- PyObject *tmp = NULL, *func;
+ PyObject *tmp = NULL;
+ PyObject *func = NULL;
PyObject *obj = NULL;
int ret = -1;
int is_text;
@@ -1419,6 +1427,12 @@ _pq_copy_out_v3(cursorObject *curs)
char *buffer;
Py_ssize_t len;
+ if (!curs->copyfile) {
+ PyErr_SetString(ProgrammingError,
+ "can't execute COPY TO: use the copy_to() method instead");
+ goto exit;
+ }
+
if (!(func = PyObject_GetAttrString(curs->copyfile, "write"))) {
Dprintf("_pq_copy_out_v3: can't get o.write");
goto exit;