mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-23 22:03:03 +01:00
Fixed bug CORE-2908 : Engine could crash or raise not expected errors working with ODS 8.x database
This commit is contained in:
parent
002ad77f15
commit
1c61e94581
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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<jrd_rel*>* vector = dbb->dbb_relations;
|
||||
|
||||
const int* fld;
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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];
|
||||
|
@ -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 */
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user