From fc7aba89f9f1b89d5712c6269ef568395007aca9 Mon Sep 17 00:00:00 2001 From: Hyung-Gyu Ryoo Date: Thu, 14 Mar 2024 18:07:14 +0800 Subject: [PATCH] [CBRD-25248] Server crash for Java SPs running a SELECT statement with 'WHERE 0 <> 0' clause (#5017) (#5037) http://jira.cubrid.org/browse/CBRD-25248 For false query such as 'SELECT * FROM db_class WHERE 0 <> 0', dummy query id is set. I've changed to set the query_id as NULL_QUERY_ID if a query is not executed (tuple_count <= 0). backport of #5017 --- src/method/method_invoke_group.cpp | 6 ++++++ src/method/method_invoke_java.cpp | 5 +---- src/method/method_query_handler.cpp | 9 ++++++++- src/method/method_runtime_context.cpp | 3 +-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/method/method_invoke_group.cpp b/src/method/method_invoke_group.cpp index 8b54d4d25ab..64a4f4208ea 100644 --- a/src/method/method_invoke_group.cpp +++ b/src/method/method_invoke_group.cpp @@ -343,6 +343,12 @@ namespace cubmethod query_cursor * method_invoke_group::create_cursor (QUERY_ID query_id, bool oid_included) { + if (query_id == NULL_QUERY_ID || query_id >= SHRT_MAX) + { + // false query e.g) SELECT * FROM db_class WHERE 0 <> 0 + return nullptr; + } + m_cursor_set.insert (query_id); return m_rctx->create_cursor (m_thread_p, query_id, oid_included); } diff --git a/src/method/method_invoke_java.cpp b/src/method/method_invoke_java.cpp index c45973df963..bbb7ae2c0c7 100644 --- a/src/method/method_invoke_java.cpp +++ b/src/method/method_invoke_java.cpp @@ -451,9 +451,7 @@ namespace cubmethod { std::uint64_t qid = current_result_info.query_id; bool is_oid_included = current_result_info.include_oid; - query_cursor *cursor = m_group->create_cursor (qid, is_oid_included); - - assert (cursor != nullptr); + (void) m_group->create_cursor (qid, is_oid_included); } } @@ -496,7 +494,6 @@ namespace cubmethod } fetch_info info; - int i = 0; SCAN_CODE s_code = S_SUCCESS; while (s_code == S_SUCCESS) diff --git a/src/method/method_query_handler.cpp b/src/method/method_query_handler.cpp index 7aa9683a6f7..449de8b4903 100644 --- a/src/method/method_query_handler.cpp +++ b/src/method/method_query_handler.cpp @@ -523,7 +523,14 @@ namespace cubmethod if (qres && qres->type == T_SELECT) { - result_info.query_id = qres->res.s.query_id; + if (qresult.tuple_count > 0) + { + result_info.query_id = qres->res.s.query_id; + } + else + { + result_info.query_id = NULL_QUERY_ID; // initialized value + } } return error; } diff --git a/src/method/method_runtime_context.cpp b/src/method/method_runtime_context.cpp index e635bff9c7e..de2b2aab1a0 100644 --- a/src/method/method_runtime_context.cpp +++ b/src/method/method_runtime_context.cpp @@ -259,8 +259,7 @@ namespace cubmethod { if (query_id == NULL_QUERY_ID || query_id >= SHRT_MAX) { - // something wrong! - assert (false); + // false query e.g) SELECT * FROM db_class WHERE 0 <> 0 return nullptr; }