From 7a7c6cb95b452b6aafab6b104673d3f65eb28454 Mon Sep 17 00:00:00 2001 From: aafemt Date: Tue, 23 Feb 2016 16:18:38 +0000 Subject: [PATCH] Some more cases of CORE-5112 as pointed by Dmitry Yemanov --- lang_helpers/gds_codes.ftn | 2 ++ lang_helpers/gds_codes.pas | 2 ++ src/dsql/dsql.cpp | 66 ++++++++++++++++++++----------------- src/include/gen/codetext.h | 1 + src/include/gen/iberror.h | 6 ++-- src/include/gen/msgs.h | 1 + src/include/gen/sql_code.h | 1 + src/include/gen/sql_state.h | 1 + src/msgs/facilities2.sql | 2 +- src/msgs/messages2.sql | 1 + src/msgs/system_errors2.sql | 1 + 11 files changed, 51 insertions(+), 33 deletions(-) diff --git a/lang_helpers/gds_codes.ftn b/lang_helpers/gds_codes.ftn index 729d4919eb..6b7c03a59c 100644 --- a/lang_helpers/gds_codes.ftn +++ b/lang_helpers/gds_codes.ftn @@ -1758,6 +1758,8 @@ C -- PARAMETER (GDS__dsql_no_input_sqlda = 336003109) INTEGER*4 GDS__dsql_no_output_sqlda PARAMETER (GDS__dsql_no_output_sqlda = 336003110) + INTEGER*4 GDS__dsql_wrong_param_num + PARAMETER (GDS__dsql_wrong_param_num = 336003111) INTEGER*4 GDS__dyn_filter_not_found PARAMETER (GDS__dyn_filter_not_found = 336068645) INTEGER*4 GDS__dyn_func_not_found diff --git a/lang_helpers/gds_codes.pas b/lang_helpers/gds_codes.pas index 47edb38d9d..ae91e1f60b 100644 --- a/lang_helpers/gds_codes.pas +++ b/lang_helpers/gds_codes.pas @@ -1753,6 +1753,8 @@ const gds_dsql_no_input_sqlda = 336003109; isc_dsql_no_output_sqlda = 336003110; gds_dsql_no_output_sqlda = 336003110; + isc_dsql_wrong_param_num = 336003111; + gds_dsql_wrong_param_num = 336003111; isc_dyn_filter_not_found = 336068645; gds_dyn_filter_not_found = 336068645; isc_dyn_func_not_found = 336068649; diff --git a/src/dsql/dsql.cpp b/src/dsql/dsql.cpp index 3ada37901b..ce717a2558 100644 --- a/src/dsql/dsql.cpp +++ b/src/dsql/dsql.cpp @@ -997,17 +997,23 @@ static void map_in_out(thread_db* tdbb, dsql_req* request, bool toExternal, cons // Sanity check - if (count && !(toExternal ? dsql_msg_buf : in_dsql_msg_buf)) + if (count) { - ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-804) << - Arg::Gds(isc_dsql_sqlda_err) -#ifdef DEV_BUILD - << Arg::Gds(isc_random) << "Missing message data buffer" -#endif - ); + if (toExternal) + { + if (dsql_msg_buf == NULL) + { + ERRD_post(Arg::Gds(isc_dsql_no_output_sqlda)); + } + } + else + if (in_dsql_msg_buf == NULL) + { + ERRD_post(Arg::Gds(isc_dsql_no_input_sqlda)); + } } - bool err = false; + USHORT count2 = 0; for (FB_SIZE_T i = 0; i < message->msg_parameters.getCount(); ++i) { @@ -1022,11 +1028,18 @@ static void map_in_out(thread_db* tdbb, dsql_req* request, bool toExternal, cons desc.clear(); //ULONG length = (IPTR) desc.dsc_address + desc.dsc_length; - - if (/*length > msg_length || */!desc.dsc_dtype) + //if (length > msg_length) + //{ + // ERRD_post(Arg::Gds(isc_dsql_sqlda_err) + // << Arg::Gds(isc_random) << "Message buffer too short" + // ); + //} + if (!desc.dsc_dtype) { - err = true; - break; + ERRD_post(Arg::Gds(isc_dsql_sqlda_err) + << Arg::Gds(isc_dsql_datatype_err) + << Arg::Gds(isc_dsql_sqlvar_index) << Arg::Num(parameter->par_index-1) + ); } UCHAR* msgBuffer = request->req_msg_buffers[parameter->par_message->msg_buffer_number]; @@ -1045,8 +1058,9 @@ static void map_in_out(thread_db* tdbb, dsql_req* request, bool toExternal, cons length = null_offset + sizeof(SSHORT); if (length > msg_length) { - err = true; - break; + ERRD_post(Arg::Gds(isc_dsql_sqlda_err) + << Arg::Gds(isc_random) << "Message buffer too short" + ); } */ @@ -1089,20 +1103,14 @@ static void map_in_out(thread_db* tdbb, dsql_req* request, bool toExternal, cons else memset(parDesc.dsc_address, 0, parDesc.dsc_length); - count--; + ++count2; } } - // If we got here because the loop was exited early or if part of the - // message given to us hasn't been used, complain. - - if (err || count) + if (count != count2) { - ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-804) << - Arg::Gds(isc_dsql_sqlda_err) -#ifdef DEV_BUILD - << Arg::Gds(isc_random) << (err ? "Message buffer too short" : "Wrong number of message parameters") -#endif + ERRD_post(Arg::Gds(isc_dsql_sqlda_err) << + Arg::Gds(isc_dsql_wrong_param_num) << Arg::Num(count) <getCount(&st); checkD(&st); - if (count != parameters.getCount()) + unsigned count2 = parameters.getCount(); + if (count != count2) { - ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-804) << - Arg::Gds(isc_dsql_sqlda_err) -#ifdef DEV_BUILD - << Arg::Gds(isc_random) << "Wrong number of message parameters" -#endif + ERRD_post(Arg::Gds(isc_dsql_sqlda_err) << + Arg::Gds(isc_dsql_wrong_param_num) <