Skip to content

Commit

Permalink
Fixed bug CORE-2908 : Engine could crash or raise not expected errors…
Browse files Browse the repository at this point in the history
… working with ODS 8.x database
  • Loading branch information
hvlad committed Mar 6, 2010
1 parent 002ad77 commit 1c61e94
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/jrd/cmp.cpp
Expand Up @@ -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;
}

Expand Down
10 changes: 1 addition & 9 deletions src/jrd/dfw.epp
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions src/jrd/ini.epp
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/jrd/jrd.h
Expand Up @@ -242,6 +242,7 @@ class Database : private pool_alloc<type_dbb>
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.
Expand Down
17 changes: 2 additions & 15 deletions src/jrd/met.epp
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/jrd/validation.cpp
Expand Up @@ -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];
Expand Down
3 changes: 2 additions & 1 deletion src/jrd/vio.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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 */
}
Expand Down

0 comments on commit 1c61e94

Please sign in to comment.