2067da
From 1c623e3b07128e78362911ff5754e7eee57fa8bb Mon Sep 17 00:00:00 2001
2067da
From: Remi Collet <remi@php.net>
2067da
Date: Fri, 31 May 2013 08:39:32 +0200
2067da
Subject: [PATCH] Fixed Bug #64949 (Buffer overflow in _pdo_pgsql_error)
2067da
2067da
There is a lot of call such as:
2067da
	pdo_pgsql_error(dbh, PGRES_FATAL_ERROR, "Copy command failed");
2067da
Where the 3rd paramater is a error message string where a sqlstate (5 chars)
2067da
is expected. This cause a segfault in copy_from.phpt and copy_to.phpt.
2067da
2067da
This is only a sanity check to avoid buffer overflow, but obviously this
2067da
calls need to be fixed (using NULL or a correct sqlstate).
2067da
---
2067da
 NEWS                         | 3 +++
2067da
 ext/pdo_pgsql/pgsql_driver.c | 2 +-
2067da
 2 files changed, 4 insertions(+), 1 deletion(-)
2067da
2067da
diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c
2067da
index 645fd36..55f4418 100644
2067da
--- a/ext/pdo_pgsql/pgsql_driver.c
2067da
+++ b/ext/pdo_pgsql/pgsql_driver.c
2067da
@@ -76,7 +76,7 @@ int _pdo_pgsql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, int errcode, const char *
2067da
 		einfo->errmsg = NULL;
2067da
 	}
2067da
 
2067da
-	if (sqlstate == NULL) {
2067da
+	if (sqlstate == NULL || strlen(sqlstate) >= sizeof(pdo_error_type)) {
2067da
 		strcpy(*pdo_err, "HY000");
2067da
 	}
2067da
 	else {
2067da
-- 
2067da
1.7.11.5
2067da