summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Di Gregorio <fog@initd.org>2006-06-18 05:57:01 +0000
committerFederico Di Gregorio <fog@initd.org>2006-06-18 05:57:01 +0000
commitb9fcde1b39edaebb0ace2e4e9f5632d2962648c7 (patch)
tree8a4281017b7c0314d6de7545c01dc8d00bac61f3
parentcf7701a151d5be665de4847344fa7b3e90a44f5a (diff)
downloadpsycopg2-b9fcde1b39edaebb0ace2e4e9f5632d2962648c7.tar.gz
Fixed segfault in Binary/QString.
-rw-r--r--ChangeLog8
-rw-r--r--psycopg/adapter_binary.c12
-rw-r--r--psycopg/adapter_qstring.c12
3 files changed, 18 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index fc9a8b1..6497f4e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2006-06-18 Federico Di Gregorio <fog@initd.org>
+
+ * psycopg/adapter_binary.c: same as below.
+
+ * psycopg/adapter_qstring.c: does not segfault anymore if
+ .getquoted() is called without preparing the qstring with
+ the connection.
+
2006-06-15 Federico Di Gregorio <fog@initd.org>
* psycopg/typecast_basic.c: fixed problem with bogus
diff --git a/psycopg/adapter_binary.c b/psycopg/adapter_binary.c
index b853890..e380b2b 100644
--- a/psycopg/adapter_binary.c
+++ b/psycopg/adapter_binary.c
@@ -44,13 +44,11 @@ binary_escape(unsigned char *from, unsigned int from_length,
#if PG_MAJOR_VERSION > 8 || \
(PG_MAJOR_VERSION == 8 && PG_MINOR_VERSION > 1) || \
(PG_MAJOR_VERSION == 8 && PG_MINOR_VERSION == 1 && PG_PATCH_VERSION >= 4)
- return PQescapeByteaConn(conn, from, from_length, to_length);
-#else
-#ifdef __GNUC__
-#warning "YOUR POSTGRESQL VERSION IS TOO OLD AND IT CAN BE INSECURE"
-#endif
- return PQescapeBytea(from, from_length, to_length);
+ if (conn)
+ return PQescapeByteaConn(conn, from, from_length, to_length);
+ else
#endif
+ return PQescapeBytea(from, from_length, to_length);
}
#else
static unsigned char *
@@ -144,7 +142,7 @@ binary_quote(binaryObject *self)
/* escape and build quoted buffer */
PyObject_AsCharBuffer(self->wrapped, &buffer, &buffer_len);
to = (char *)binary_escape((unsigned char*)buffer, buffer_len, &len,
- ((connectionObject*)self->conn)->pgconn);
+ self->conn ? ((connectionObject*)self->conn)->pgconn : NULL);
if (to == NULL) {
PyErr_NoMemory();
return NULL;
diff --git a/psycopg/adapter_qstring.c b/psycopg/adapter_qstring.c
index 7caed9a..2eaf7f3 100644
--- a/psycopg/adapter_qstring.c
+++ b/psycopg/adapter_qstring.c
@@ -45,13 +45,11 @@ qstring_escape(char *to, char *from, size_t len, PGconn *conn)
(PG_MAJOR_VERSION == 8 && PG_MINOR_VERSION > 1) || \
(PG_MAJOR_VERSION == 8 && PG_MINOR_VERSION == 1 && PG_PATCH_VERSION >= 4)
int err;
- return PQescapeStringConn(conn, to, from, len, &err);
-#else
-#ifdef __GNUC__
-#warning "YOUR POSTGRESQL VERSION IS TOO OLD AND IT CAN BE INSECURE"
-#endif
- return PQescapeString(to, from, len);
+ if (conn)
+ return PQescapeStringConn(conn, to, from, len, &err);
+ else
#endif
+ return PQescapeString(to, from, len);
}
#else
static size_t
@@ -149,7 +147,7 @@ qstring_quote(qstringObject *self)
Py_BEGIN_ALLOW_THREADS;
len = qstring_escape(buffer+1, s, len,
- ((connectionObject*)self->conn)->pgconn);
+ self->conn ? ((connectionObject*)self->conn)->pgconn : NULL);
buffer[0] = '\'' ; buffer[len+1] = '\'';
Py_END_ALLOW_THREADS;