From 1c61e9458117e82dfc4e91a12aa4278648b7f680 Mon Sep 17 00:00:00 2001 From: hvlad Date: Sat, 6 Mar 2010 14:05:15 +0000 Subject: [PATCH] Fixed bug CORE-2908 : Engine could crash or raise not expected errors working with ODS 8.x database --- src/jrd/cmp.cpp | 2 +- src/jrd/dfw.epp | 10 +--------- src/jrd/ini.epp | 8 ++++++++ src/jrd/jrd.h | 1 + src/jrd/met.epp | 17 ++--------------- src/jrd/validation.cpp | 2 +- src/jrd/vio.cpp | 3 ++- 7 files changed, 16 insertions(+), 27 deletions(-) diff --git a/src/jrd/cmp.cpp b/src/jrd/cmp.cpp index a356f3d703..c6bf8434b0 100644 --- a/src/jrd/cmp.cpp +++ b/src/jrd/cmp.cpp @@ -1955,7 +1955,7 @@ IndexLock* CMP_get_index_lock(thread_db* tdbb, jrd_rel* relation, USHORT id) DEV_BLKCHK(relation, type_rel); - if (relation->rel_id < (USHORT) rel_MAX) { + if (relation->rel_id <= dbb->dbb_max_sys_rel) { return NULL; } diff --git a/src/jrd/dfw.epp b/src/jrd/dfw.epp index d5019078ee..110a40bf27 100644 --- a/src/jrd/dfw.epp +++ b/src/jrd/dfw.epp @@ -124,7 +124,6 @@ /* Define range of user relation ids */ -const int MIN_RELATION_ID = rel_MAX; const int MAX_RELATION_ID = 32767; const int COMPUTED_FLAG = 128; @@ -2407,15 +2406,8 @@ static bool create_relation(thread_db* tdbb, SET_TDBB(tdbb); Database* dbb = tdbb->getDatabase(); - const USHORT major_version = dbb->dbb_ods_version; - const USHORT minor_original = dbb->dbb_minor_original; - - USHORT local_min_relation_id; - if (ENCODE_ODS(major_version, minor_original) < ODS_9_0) - local_min_relation_id = MIN_RELATION_ID; - else - local_min_relation_id = USER_DEF_REL_INIT_ID; + USHORT local_min_relation_id = dbb->dbb_max_sys_rel + 1; switch (phase) { case 0: diff --git a/src/jrd/ini.epp b/src/jrd/ini.epp index 32cc7254b7..c889434479 100644 --- a/src/jrd/ini.epp +++ b/src/jrd/ini.epp @@ -587,6 +587,14 @@ void INI_init2(void) const USHORT major_version = dbb->dbb_ods_version; const USHORT minor_original = dbb->dbb_minor_original; + + if (ENCODE_ODS(major_version, minor_original) < ODS_9_0) { + dbb->dbb_max_sys_rel = USER_REL_INIT_ID_ODS8 - 1; + } + else { + dbb->dbb_max_sys_rel = USER_DEF_REL_INIT_ID - 1; + } + vec* vector = dbb->dbb_relations; const int* fld; diff --git a/src/jrd/jrd.h b/src/jrd/jrd.h index da6e96e401..93c2e497c9 100644 --- a/src/jrd/jrd.h +++ b/src/jrd/jrd.h @@ -242,6 +242,7 @@ public: USHORT dbb_dp_per_pp; // data pages per pointer page USHORT dbb_max_records; // max record per data page USHORT dbb_max_idx; // max number of indexes on a root page + USHORT dbb_max_sys_rel; // max id of system relation USHORT dbb_use_count; // active count of threads USHORT dbb_shutdown_delay; // seconds until forced shutdown. // Set in shut.cpp but not tested yet. diff --git a/src/jrd/met.epp b/src/jrd/met.epp index 687686564a..2bf1e6e1ea 100644 --- a/src/jrd/met.epp +++ b/src/jrd/met.epp @@ -2563,7 +2563,7 @@ jrd_rel* MET_lookup_relation_id(thread_db* tdbb, SLONG id, bool return_deleted) /* System relations are above suspicion */ - if (id < (int) rel_MAX) + if (id <= (int) dbb->dbb_max_sys_rel) { fb_assert(id < MAX_USHORT); return MET_relation(tdbb, (USHORT) id); @@ -3290,19 +3290,6 @@ jrd_rel* MET_relation(thread_db* tdbb, USHORT id) return relation; } - const USHORT major_version = dbb->dbb_ods_version; - const USHORT minor_original = dbb->dbb_minor_original; - -/* From ODS 9 onwards, the first 128 relation IDS have been - reserved for system relations */ - USHORT max_sys_rel; - if (ENCODE_ODS(major_version, minor_original) < ODS_9_0) { - max_sys_rel = USER_REL_INIT_ID_ODS8 - 1; - } - else { - max_sys_rel = USER_DEF_REL_INIT_ID - 1; - } - relation = FB_NEW(*dbb->dbb_permanent) jrd_rel(*dbb->dbb_permanent); (*vector)[id] = relation; relation->rel_id = id; @@ -3321,7 +3308,7 @@ jrd_rel* MET_relation(thread_db* tdbb, USHORT id) } // This should check system flag instead. - if (relation->rel_id <= max_sys_rel) { + if (relation->rel_id <= dbb->dbb_max_sys_rel) { return relation; } diff --git a/src/jrd/validation.cpp b/src/jrd/validation.cpp index a7ebf4c785..d863934dba 100644 --- a/src/jrd/validation.cpp +++ b/src/jrd/validation.cpp @@ -1162,7 +1162,7 @@ static void walk_database(thread_db* tdbb, vdr* control) for (USHORT i = 0; (vector = dbb->dbb_relations) && i < vector->count(); i++) { #ifdef DEBUG_VAL_VERBOSE - if (i >= 32 /* rel_MAX */ ) // Why not system flag instead? + if (i > dbb->dbb_max_sys_rel) // Why not system flag instead? VAL_debug_level = 2; #endif jrd_rel* relation = (*vector)[i]; diff --git a/src/jrd/vio.cpp b/src/jrd/vio.cpp index e28b44e833..4b57335ff0 100644 --- a/src/jrd/vio.cpp +++ b/src/jrd/vio.cpp @@ -1148,6 +1148,7 @@ void VIO_erase(thread_db* tdbb, record_param* rpb, jrd_tra* transaction) SqlIdentifier relation_name, revokee, privilege, procedure_name; SET_TDBB(tdbb); + Database* dbb = tdbb->getDatabase(); jrd_req* request = tdbb->getRequest(); #ifdef VIO_DEBUG @@ -1212,7 +1213,7 @@ void VIO_erase(thread_db* tdbb, record_param* rpb, jrd_tra* transaction) if (EVL_field(0, rpb->rpb_record, f_rel_id, &desc2)) { id = MOV_get_long(&desc2, 0); - if (id < (int) rel_MAX) + if (id <= dbb->dbb_max_sys_rel) { IBERROR(187); /* msg 187 cannot delete system relations */ }