From 23241eb2d31ea1337c425401b6ae542586c4b5fa Mon Sep 17 00:00:00 2001 From: dimitr Date: Thu, 14 Jul 2011 15:54:27 +0000 Subject: [PATCH] Front ported CORE-3554: Server crashes during prepare or throws incorrect parsing error if the remotely passed SQL query is empty. --- src/dsql/dsql.cpp | 36 +++++++++--------------------------- src/remote/interface.cpp | 20 ++++++++++++++++++-- src/remote/protocol.cpp | 7 +++++++ 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/src/dsql/dsql.cpp b/src/dsql/dsql.cpp index ded72d7b4d..69003161ce 100644 --- a/src/dsql/dsql.cpp +++ b/src/dsql/dsql.cpp @@ -682,17 +682,6 @@ void DSQL_prepare(thread_db* tdbb, dsql_req* request = NULL; - if (!string) { - ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) << - // Unexpected end of command - // CVC: Nothing will be line 1, column 1 for the user. - Arg::Gds(isc_command_end_err2) << Arg::Num(1) << Arg::Num(1)); - } - - if (!length) { - length = strlen(string); - } - try { // Figure out which parser version to use @@ -1098,17 +1087,6 @@ static void execute_immediate(thread_db* tdbb, { SET_TDBB(tdbb); - if (!string) { - ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) << - // Unexpected end of command - // CVC: Nothing will be line 1, column 1 for the user. - Arg::Gds(isc_command_end_err2) << Arg::Num(1) << Arg::Num(1)); - } - - if (!length) { - length = strlen(string); - } - dsql_dbb* const database = init(attachment); dsql_req* request = NULL; @@ -2558,17 +2536,21 @@ static dsql_req* prepare(thread_db* tdbb, dsql_dbb* database, jrd_tra* transacti Arg::Gds(isc_wish_list)); } - if (!string) { + if (string && !string_length) + { + size_t sql_length = strlen(string); + if (sql_length > MAX_USHORT) + sql_length = MAX_USHORT; + string_length = static_cast(sql_length); + } + + if (!string || !string_length) { ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) << // Unexpected end of command // CVC: Nothing will be line 1, column 1 for the user. Arg::Gds(isc_command_end_err2) << Arg::Num(1) << Arg::Num(1)); } - if (!string_length) { - string_length = strlen(string); - } - // Get rid of the trailing ";" if there is one. for (const TEXT* p = string + string_length; p-- > string;) diff --git a/src/remote/interface.cpp b/src/remote/interface.cpp index bc1648f8ea..f8b091c28c 100644 --- a/src/remote/interface.cpp +++ b/src/remote/interface.cpp @@ -1496,6 +1496,14 @@ ISC_STATUS GDS_DSQL_EXECUTE_IMMED2(ISC_STATUS* user_status, rdb->set_status_vector(user_status); + if (!length) + { + size_t sql_length = strlen(string); + if (sql_length > MAX_USHORT) + sql_length = MAX_USHORT; + length = static_cast(sql_length); + } + if (dialect > 10) { // dimitr: adjust dialect received after @@ -1588,7 +1596,7 @@ ISC_STATUS GDS_DSQL_EXECUTE_IMMED2(ISC_STATUS* user_status, P_SQLST* ex_now = &packet->p_sqlst; ex_now->p_sqlst_transaction = transaction ? transaction->rtr_id : 0; ex_now->p_sqlst_SQL_dialect = dialect; - ex_now->p_sqlst_SQL_str.cstr_length = length ? length : strlen(string); + ex_now->p_sqlst_SQL_str.cstr_length = length; ex_now->p_sqlst_SQL_str.cstr_address = reinterpret_cast(string); ex_now->p_sqlst_items.cstr_length = 0; ex_now->p_sqlst_buffer_length = 0; @@ -2181,6 +2189,14 @@ ISC_STATUS GDS_DSQL_PREPARE(ISC_STATUS* user_status, Rtr** rtr_handle, } rdb->set_status_vector(user_status); + if (!length) + { + size_t sql_length = strlen(string); + if (sql_length > MAX_USHORT) + sql_length = MAX_USHORT; + length = static_cast(sql_length); + } + if (dialect > 10) { // dimitr: adjust dialect received after @@ -2223,7 +2239,7 @@ ISC_STATUS GDS_DSQL_PREPARE(ISC_STATUS* user_status, Rtr** rtr_handle, prepare->p_sqlst_transaction = transaction ? transaction->rtr_id : 0; prepare->p_sqlst_statement = statement->rsr_id; prepare->p_sqlst_SQL_dialect = dialect; - prepare->p_sqlst_SQL_str.cstr_length = length ? length : strlen(string); + prepare->p_sqlst_SQL_str.cstr_length = length; prepare->p_sqlst_SQL_str.cstr_address = reinterpret_cast(string); prepare->p_sqlst_items.cstr_length = item_length; prepare->p_sqlst_items.cstr_address = items; diff --git a/src/remote/protocol.cpp b/src/remote/protocol.cpp index 3d6aceb262..84dd20e065 100644 --- a/src/remote/protocol.cpp +++ b/src/remote/protocol.cpp @@ -848,7 +848,14 @@ static bool alloc_cstring(XDR* xdrs, CSTRING* cstring) **************************************/ if (!cstring->cstr_length) + { + if (cstring->cstr_allocated) + *cstring->cstr_address = '\0'; + else + cstring->cstr_address = NULL; + return true; + } if (cstring->cstr_length > cstring->cstr_allocated && cstring->cstr_allocated) {