From bfb00b86fd5b3b7f4e7bf612180b53757f6f8f5d Mon Sep 17 00:00:00 2001 From: Federico Di Gregorio Date: Fri, 26 May 2006 05:22:49 +0000 Subject: [PATCH] Better PostgreSQL version check. --- ChangeLog | 4 ++++ psycopg/adapter_binary.c | 12 +++++++----- psycopg/adapter_qstring.c | 14 ++++++++------ 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 712c55e9..d00bb077 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2006-05-26 Federico Di Gregorio + + * Applied better PostgreSQL patch from AA. + 2006-05-24 Federico Di Gregorio * Enabled 8.1.4 security fix only when the version is >= 8.1.4, fall diff --git a/psycopg/adapter_binary.c b/psycopg/adapter_binary.c index 48489c2c..852e6289 100644 --- a/psycopg/adapter_binary.c +++ b/psycopg/adapter_binary.c @@ -41,12 +41,14 @@ 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 +#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 +#warning "YOUR POSTGRESQL VERSION IS TOO OLD AND IT CAN BE INSECURE" + return PQescapeBytea(from, from_length, to_length); #endif - return PQescapeBytea(from, from_length, to_length); } #else static unsigned char * diff --git a/psycopg/adapter_qstring.c b/psycopg/adapter_qstring.c index d86540e3..ca627d75 100644 --- a/psycopg/adapter_qstring.c +++ b/psycopg/adapter_qstring.c @@ -41,13 +41,15 @@ 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 +#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) + int err; + return PQescapeStringConn(conn, to, from, len, &err); +#else +#warning "YOUR POSTGRESQL VERSION IS TOO OLD AND IT CAN BE INSECURE" + return PQescapeString(to, from, len); #endif - return PQescapeString(to, from, len); } #else static size_t