php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #52512
Patch odbc_execute_errorhandling.patch revision 2010-08-02 08:58 UTC by mkoegler at auto dot tuwien dot ac dot at

Patch odbc_execute_errorhandling.patch for ODBC related Bug #52512

Patch version 2010-08-02 08:58 UTC

Return to Bug #52512 | Download this patch
Patch Revisions:

Developer: mkoegler@auto.tuwien.ac.at

--- ext/odbc/php_odbc.orig.c	2010-08-02 10:04:21.814834910 +0200
+++ ext/odbc/php_odbc.c	2010-08-02 10:27:44.126585116 +0200
@@ -1263,11 +1263,18 @@
 
 		zend_hash_internal_pointer_reset(Z_ARRVAL_P(pv_param_arr));
 		params = (params_t *)safe_emalloc(sizeof(params_t), result->numparams, 0);
+		for(i = 0; i < result->numparams; i++)
+			params[i].fp = -1;
 		
 		for(i = 1; i <= result->numparams; i++) {
 			if (zend_hash_get_current_data(Z_ARRVAL_P(pv_param_arr), (void **) &tmp) == FAILURE) {
 				php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error getting parameter");
 				SQLFreeStmt(result->stmt,SQL_RESET_PARAMS);
+				for(i = 0; i < result->numparams; i++) {
+					if (params[i].fp != -1) {
+						close(params[i].fp);
+					}
+				}
 				efree(params);
 				RETURN_FALSE;
 			}
@@ -1277,13 +1284,29 @@
 			if (Z_TYPE_PP(tmp) != IS_STRING) {
 				php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter");
 				SQLFreeStmt(result->stmt, SQL_RESET_PARAMS);
+				for(i = 0; i < result->numparams; i++) {
+					if (params[i].fp != -1) {
+						close(params[i].fp);
+					}
+				}
 				efree(params);
 				RETURN_FALSE;
 			}
 			
-			SQLDescribeParam(result->stmt, (SQLUSMALLINT)i, &sqltype, &precision, &scale, &nullable);
+			rc = SQLDescribeParam(result->stmt, (SQLUSMALLINT)i, &sqltype, &precision, &scale, &nullable);
 			params[i-1].vallen = Z_STRLEN_PP(tmp);
 			params[i-1].fp = -1;
+			if (rc == SQL_ERROR) {
+				odbc_sql_error(result->conn_ptr, result->stmt, "SQLDescribeParameter");	
+				SQLFreeStmt(result->stmt, SQL_RESET_PARAMS);
+				for(i = 0; i < result->numparams; i++) {
+					if (params[i].fp != -1) {
+						close(params[i].fp);
+					}
+				}
+				efree(params);
+				RETURN_FALSE;
+			}
 
 			if (IS_SQL_BINARY(sqltype)) {
 				ctype = SQL_C_BINARY;
@@ -1300,6 +1323,11 @@
 				/* Check for safe mode. */
 				if (PG(safe_mode) && (!php_checkuid(filename, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
 					efree(filename);
+					for(i = 0; i < result->numparams; i++) {
+						if (params[i].fp != -1) {
+							close(params[i].fp);
+						}
+					}
 					efree(params);
 					RETURN_FALSE;
 				}
@@ -1307,6 +1335,11 @@
 				/* Check the basedir */
 				if (php_check_open_basedir(filename TSRMLS_CC)) {
 					efree(filename);
+					for(i = 0; i < result->numparams; i++) {
+						if (params[i].fp != -1) {
+							close(params[i].fp);
+						}
+					}
 					efree(params);
 					RETURN_FALSE;
 				}
@@ -1345,6 +1378,17 @@
 									  Z_STRVAL_PP(tmp), 0,
 									  &params[i-1].vallen);
 			}
+			if (rc == SQL_ERROR) {
+				odbc_sql_error(result->conn_ptr, result->stmt, "SQLBindParameter");	
+				SQLFreeStmt(result->stmt, SQL_RESET_PARAMS);
+				for(i = 0; i < result->numparams; i++) {
+					if (params[i].fp != -1) {
+						close(params[i].fp);
+					}
+				}
+				efree(params);
+				RETURN_FALSE;
+			}
 			zend_hash_move_forward(Z_ARRVAL_P(pv_param_arr));
 		}
 	}
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 13:01:29 2024 UTC