From e5a3767089a1d997a0ea292de531ad5ff072089f Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Fri, 3 Nov 2017 10:00:08 -0700 Subject: [PATCH] Added error handling for LOB types as output parameters --- source/pdo_sqlsrv/pdo_util.cpp | 4 + source/shared/core_sqlsrv.h | 1 + source/shared/core_stmt.cpp | 6 + source/sqlsrv/util.cpp | 5 + .../srv_231_string_truncation_text.phpt | 133 ++++++++++++++++++ 5 files changed, 149 insertions(+) create mode 100644 test/functional/sqlsrv/srv_231_string_truncation_text.phpt diff --git a/source/pdo_sqlsrv/pdo_util.cpp b/source/pdo_sqlsrv/pdo_util.cpp index 1021fd29..6db8a363 100644 --- a/source/pdo_sqlsrv/pdo_util.cpp +++ b/source/pdo_sqlsrv/pdo_util.cpp @@ -417,6 +417,10 @@ pdo_error PDO_ERRORS[] = { PDO_SQLSRV_ERROR_CE_EMULATE_PREPARE_UNSUPPORTED, { IMSSP, (SQLCHAR*) "Parameterized statement with attribute PDO::ATTR_EMULATE_PREPARES is not supported in a Column Encryption enabled Connection.", -82, false } }, + { + SQLSRV_ERROR_OUTPUT_PARAM_TYPES_NOT_SUPPORTED, + { IMSSP, (SQLCHAR*) "Stored Procedures do not support text, ntext or image as OUTPUT parameters.", -83, false } + }, { UINT_MAX, {} } }; diff --git a/source/shared/core_sqlsrv.h b/source/shared/core_sqlsrv.h index 16ca5711..bad4b538 100644 --- a/source/shared/core_sqlsrv.h +++ b/source/shared/core_sqlsrv.h @@ -1689,6 +1689,7 @@ enum SQLSRV_ERROR_CODES { SQLSRV_ERROR_KEYSTORE_PATH_MISSING, SQLSRV_ERROR_KEYSTORE_KEY_MISSING, SQLSRV_ERROR_KEYSTORE_INVALID_VALUE, + SQLSRV_ERROR_OUTPUT_PARAM_TYPES_NOT_SUPPORTED, // Driver specific error codes starts from here. SQLSRV_ERROR_DRIVER_SPECIFIC = 1000, diff --git a/source/shared/core_stmt.cpp b/source/shared/core_stmt.cpp index 7dafef7d..1dc1dff3 100644 --- a/source/shared/core_stmt.cpp +++ b/source/shared/core_stmt.cpp @@ -422,6 +422,12 @@ void core_sqlsrv_bind_param( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT param_ // if it's an output parameter and the user asks for a certain type, we have to convert the zval to that type so // when the buffer is filled, the type is correct + CHECK_CUSTOM_ERROR( direction != SQL_PARAM_INPUT && (sql_type == SQL_LONGVARCHAR + || sql_type == SQL_WLONGVARCHAR || sql_type == SQL_LONGVARBINARY), + stmt, SQLSRV_ERROR_OUTPUT_PARAM_TYPES_NOT_SUPPORTED ){ + throw core::CoreException(); + } + if( direction == SQL_PARAM_OUTPUT ){ switch( php_out_type ) { case SQLSRV_PHPTYPE_INT: diff --git a/source/sqlsrv/util.cpp b/source/sqlsrv/util.cpp index b8dd765d..264139ea 100644 --- a/source/sqlsrv/util.cpp +++ b/source/sqlsrv/util.cpp @@ -408,6 +408,11 @@ ss_error SS_ERRORS[] = { SQLSRV_ERROR_SPECIFIED_DRIVER_NOT_FOUND, { IMSSP, (SQLCHAR*) "The specified ODBC Driver is not found.", -107, false } }, + { + SQLSRV_ERROR_OUTPUT_PARAM_TYPES_NOT_SUPPORTED, + { IMSSP, (SQLCHAR*) "Stored Procedures do not support text, ntext or image as OUTPUT parameters.", -108, false } + }, + // terminate the list of errors/warnings { UINT_MAX, {} } }; diff --git a/test/functional/sqlsrv/srv_231_string_truncation_text.phpt b/test/functional/sqlsrv/srv_231_string_truncation_text.phpt new file mode 100644 index 00000000..51c5e84b --- /dev/null +++ b/test/functional/sqlsrv/srv_231_string_truncation_text.phpt @@ -0,0 +1,133 @@ +--TEST-- +GitHub issue #231 - String truncation when binding text/ntext/image to check error messages +--ENV-- +PHPT_EXEC=true +--SKIPIF-- + +--FILE-- + + +--EXPECT-- + +Data Type: text binding as +Output parameter: Stored Procedures do not support text, ntext or image as OUTPUT parameters. +InOut parameter: Stored Procedures do not support text, ntext or image as OUTPUT parameters. + +Data Type: ntext binding as +Output parameter: Stored Procedures do not support text, ntext or image as OUTPUT parameters. +InOut parameter: Stored Procedures do not support text, ntext or image as OUTPUT parameters. + +Data Type: image binding as +Output parameter: Stored Procedures do not support text, ntext or image as OUTPUT parameters. +InOut parameter: Stored Procedures do not support text, ntext or image as OUTPUT parameters.