From 37960040c1d70c934e7c4604a745624c2431be13 Mon Sep 17 00:00:00 2001 From: Matteo Beccati Date: Fri, 25 Dec 2009 20:09:08 +0000 Subject: [PATCH] - Fixed bug #50575 (PDO_PGSQL LOBs are not compatible with PostgreSQL 8.5) # Affects 5.2 only, no need to MFB --- NEWS | 2 ++ ext/pdo_pgsql/pgsql_statement.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/NEWS b/NEWS index e43bfe841d..7ec8926a45 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,8 @@ PHP NEWS - Fixed build of mysqli with MySQL 5.5.0-m2. (Andrey) +- Fixed bug #50575 (PDO_PGSQL LOBs are not compatible with PostgreSQL 8.5). + (Matteo) - Fixed bug #50558 (Broken object model when extending tidy). (Pierrick) - Fixed bug #50540 (Crash while running ldap_next_reference test cases). (Sriram) diff --git a/ext/pdo_pgsql/pgsql_statement.c b/ext/pdo_pgsql/pgsql_statement.c index fbfdde1c07..9985b2a253 100644 --- a/ext/pdo_pgsql/pgsql_statement.c +++ b/ext/pdo_pgsql/pgsql_statement.c @@ -472,6 +472,24 @@ static int pgsql_stmt_describe(pdo_stmt_t *stmt, int colno TSRMLS_DC) */ static unsigned char *php_pdo_pgsql_unescape_bytea(unsigned char *strtext, size_t *retbuflen) { +#ifdef HAVE_PQUNESCAPEBYTEA + size_t tmp_len; + char *buffer; + char *tmp_ptr = PQunescapeBytea(strtext, &tmp_len); + + if (!tmp_ptr) { + /* PQunescapeBytea returned an error, this + function will return en empty string */ + tmp_len = 0; + buffer = emalloc(0); + } else { + buffer = emalloc(tmp_len); + memcpy(buffer, tmp_ptr, tmp_len); + PQfreemem(tmp_ptr); + } + *retbuflen = tmp_len; + return buffer; +#else size_t buflen; unsigned char *buffer, *sp, @@ -480,6 +498,7 @@ static unsigned char *php_pdo_pgsql_unescape_bytea(unsigned char *strtext, size_ if (strtext == NULL) return NULL; + buflen = strlen(strtext); /* will shrink, also we discover if * strtext */ buffer = (unsigned char *) emalloc(buflen); /* isn't NULL terminated */ @@ -549,6 +568,7 @@ static unsigned char *php_pdo_pgsql_unescape_bytea(unsigned char *strtext, size_ *retbuflen = buflen; return buffer; +#endif } static int pgsql_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, unsigned long *len, int *caller_frees TSRMLS_DC) -- 2.40.0