summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--psycopg/adapter_binary.c2
-rw-r--r--psycopg/adapter_qstring.c3
-rw-r--r--setup.py28
4 files changed, 28 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index ff907ab..712c55e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2006-05-24 Federico Di Gregorio <fog@initd.org>
+ * Enabled 8.1.4 security fix only when the version is >= 8.1.4, fall
+ back to old code otherwise.
+
* psycopg/adapter_qstring.c: now quote using PQescapeStringConn if
available.
diff --git a/psycopg/adapter_binary.c b/psycopg/adapter_binary.c
index 1a074ad..48489c2 100644
--- a/psycopg/adapter_binary.c
+++ b/psycopg/adapter_binary.c
@@ -41,9 +41,11 @@ static unsigned char *
binary_escape(unsigned char *from, unsigned int from_length,
unsigned int *to_length, PGconn *conn)
{
+#if PG_MAJOR_VERSION >= 8 && PG_MINOR_VERSION >= 1 && PG_PATCH_VERSION >= 4
if (conn)
return PQescapeByteaConn(conn, from, from_length, to_length);
else
+#endif
return PQescapeBytea(from, from_length, to_length);
}
#else
diff --git a/psycopg/adapter_qstring.c b/psycopg/adapter_qstring.c
index 50c62c8..d86540e 100644
--- a/psycopg/adapter_qstring.c
+++ b/psycopg/adapter_qstring.c
@@ -42,10 +42,11 @@ static size_t
qstring_escape(char *to, char *from, size_t len, PGconn *conn)
{
int err = 0;
-
+#if PG_MAJOR_VERSION >= 8 && PG_MINOR_VERSION >= 1 && PG_PATCH_VERSION >= 4
if (conn)
return PQescapeStringConn(conn, to, from, len, &err);
else
+#endif
return PQescapeString(to, from, len);
}
#else
diff --git a/setup.py b/setup.py
index f398328..ad74fff 100644
--- a/setup.py
+++ b/setup.py
@@ -61,6 +61,13 @@ if sys.version < '2.2.3':
DistributionMetadata.classifiers = None
DistributionMetadata.download_url = None
+def get_pg_config(kind, pg_config="pg_config"):
+ p = popen2.popen3(pg_config + " --" + kind)
+ r = p[0].readline().strip()
+ if not r:
+ raise Warning(p[2].readline())
+ return r
+
class psycopg_build_ext(build_ext):
"""Conditionally complement the setup.cfg options file.
@@ -93,13 +100,6 @@ class psycopg_build_ext(build_ext):
self.pgdir = None
self.pg_config = self.DEFAULT_PG_CONFIG
self.mx_include_dir = None
-
- def get_pg_config(self, kind):
- p = popen2.popen3(self.pg_config + " --" + kind)
- r = p[0].readline().strip()
- if not r:
- raise Warning(p[2].readline())
- return r
def get_compiler(self):
"""Return the c compiler to compile extensions.
@@ -109,6 +109,9 @@ class psycopg_build_ext(build_ext):
"""
return self.compiler or get_default_compiler()
+ def get_pg_config(self, kind):
+ return get_pg_config(kind, self.pg_config)
+
def build_extensions(self):
# Linking against this library causes psycopg2 to crash
# on Python >= 2.4. Maybe related to strdup calls, cfr.
@@ -149,6 +152,17 @@ class psycopg_build_ext(build_ext):
self.library_dirs.append(self.get_pg_config("libdir"))
self.include_dirs.append(self.get_pg_config("includedir"))
self.include_dirs.append(self.get_pg_config("includedir-server"))
+ try:
+ # Here we take a conservative approach: we suppose that
+ # *at least* PostgreSQL 7.4 is available (this is the only
+ # 7.x series supported by psycopg 2)
+ pgversion = self.get_pg_config("version").split()[1]
+ pgmajor, pgminor, pgpatch = pgversion.split('.')
+ except:
+ pgmajor, pgminor, pgpatch = 7, 4, 0
+ define_macros.append(("PG_MAJOR_VERSION", pgmajor))
+ define_macros.append(("PG_MINOR_VERSION", pgminor))
+ define_macros.append(("PG_PATCH_VERSION", pgpatch))
except Warning, w:
if self.pg_config == self.DEFAULT_PG_CONFIG:
sys.stderr.write("Warning: %s" % str(w))