8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 21:23:03 +01:00

Fix CORE-1447.

This commit is contained in:
robocop 2007-09-11 09:19:23 +00:00
parent cfb6fe3474
commit b18b0eedec

View File

@ -179,9 +179,7 @@ USHORT INF_convert(SLONG number, SCHAR* buffer)
const SCHAR* p; const SCHAR* p;
#ifndef WORDS_BIGENDIAN #ifndef WORDS_BIGENDIAN
// CVC: What's the need for an intermediate "n" here? p = reinterpret_cast<const SCHAR*>(&number);
const SLONG n = number;
p = reinterpret_cast<const SCHAR*>(&n);
*buffer++ = *p++; *buffer++ = *p++;
*buffer++ = *p++; *buffer++ = *p++;
*buffer++ = *p++; *buffer++ = *p++;
@ -229,9 +227,9 @@ int INF_database_info(const SCHAR* items,
jrd_tra* transaction = NULL; jrd_tra* transaction = NULL;
const SCHAR* const end_items = items + item_length; const SCHAR* const end_items = items + item_length;
const SCHAR* const end = info + output_length; const SCHAR* const end = info + output_length;
const SCHAR* const end_buf = buffer + sizeof(buffer);
Attachment* err_att = 0; const Attachment* err_att = tdbb->tdbb_attachment;
Attachment* att = 0;
const SCHAR* q; const SCHAR* q;
while (items < end_items && *items != isc_info_end) { while (items < end_items && *items != isc_info_end) {
@ -444,17 +442,28 @@ int INF_database_info(const SCHAR* items,
case isc_info_db_id: case isc_info_db_id:
{ {
// May be simpler to code using a server-side version of isql's Extender class.
const Firebird::PathName& str_fn = dbb->dbb_database_name; const Firebird::PathName& str_fn = dbb->dbb_database_name;
STUFF(p, 2); STUFF(p, 2);
SSHORT l = str_fn.length(); USHORT len = str_fn.length();
*p++ = l; if (p + len + 1 >= end_buf)
for (q = str_fn.c_str(); *q;) len = end_buf - p - 1;
*p++ = *q++; if (len > 255)
SCHAR site[256]; len = 255; // Cannot put more in one byte, will truncate instead.
ISC_get_host(site, sizeof(site)); *p++ = len;
*p++ = l = strlen(site); memcpy(p, str_fn.c_str(), len);
for (q = site; *q;) p += len;
*p++ = *q++; if (p + 2 < end_buf)
{
SCHAR site[256];
ISC_get_host(site, sizeof(site));
len = strlen(site);
if (p + len + 1 >= end_buf)
len = end_buf - p - 1;
*p++ = len;
memcpy(p, site, len);
p += len;
}
length = p - buffer; length = p - buffer;
break; break;
} }
@ -542,11 +551,14 @@ int INF_database_info(const SCHAR* items,
break; break;
case isc_info_user_names: case isc_info_user_names:
// Assumes user names will be smaller than sizeof(buffer) - 1.
if (!(tdbb->tdbb_attachment->locksmith())) { if (!(tdbb->tdbb_attachment->locksmith())) {
const UserId* user = tdbb->tdbb_attachment->att_user; const UserId* user = tdbb->tdbb_attachment->att_user;
Firebird::string uname((user && user->usr_user_name.hasData()) ? user->usr_user_name.c_str() : "<Unknown>"); const char* uname = (user && user->usr_user_name.hasData()) ? user->usr_user_name.c_str() : "<Unknown>";
uname.insert(0, char(uname.length())); const SSHORT len = strlen(uname);
info = INF_put_item(item, uname.length(), uname.c_str(), info, end); *p++ = len;
memcpy(p, uname, len);
info = INF_put_item(item, len + 1, buffer, info, end);
if (!info) { if (!info) {
if (transaction) if (transaction)
TRA_commit(tdbb, transaction, false); TRA_commit(tdbb, transaction, false);
@ -554,7 +566,9 @@ int INF_database_info(const SCHAR* items,
} }
continue; continue;
} }
for (att = dbb->dbb_attachments; att; att = att->att_next) { { // scope for VC6
for (const Attachment* att = dbb->dbb_attachments; att; att = att->att_next)
{
if (att->att_flags & ATT_shutdown) if (att->att_flags & ATT_shutdown)
continue; continue;
@ -563,12 +577,10 @@ int INF_database_info(const SCHAR* items,
const char* user_name = user->usr_user_name.hasData() ? const char* user_name = user->usr_user_name.hasData() ?
user->usr_user_name.c_str() : "(Firebird Worker Thread)"; user->usr_user_name.c_str() : "(Firebird Worker Thread)";
p = buffer; p = buffer;
SSHORT l = strlen (user_name); const SSHORT len = strlen(user_name);
*p++ = l; *p++ = len;
for (q = user_name; l; l--) memcpy(p, user_name, len);
*p++ = *q++; info = INF_put_item(item, len + 1, buffer, info, end);
length = p - buffer;
info = INF_put_item(item, length, buffer, info, end);
if (!info) { if (!info) {
if (transaction) if (transaction)
TRA_commit(tdbb, transaction, false); TRA_commit(tdbb, transaction, false);
@ -576,10 +588,10 @@ int INF_database_info(const SCHAR* items,
} }
} }
} }
} // end scope for VC6
continue; continue;
case isc_info_page_errors: case isc_info_page_errors:
err_att = tdbb->tdbb_attachment;
if (err_att->att_val_errors) { if (err_att->att_val_errors) {
err_val = err_val =
(*err_att->att_val_errors)[VAL_PAG_WRONG_TYPE] (*err_att->att_val_errors)[VAL_PAG_WRONG_TYPE]
@ -595,7 +607,6 @@ int INF_database_info(const SCHAR* items,
break; break;
case isc_info_bpage_errors: case isc_info_bpage_errors:
err_att = tdbb->tdbb_attachment;
if (err_att->att_val_errors) { if (err_att->att_val_errors) {
err_val = err_val =
(*err_att->att_val_errors)[VAL_BLOB_INCONSISTENT] (*err_att->att_val_errors)[VAL_BLOB_INCONSISTENT]
@ -609,7 +620,6 @@ int INF_database_info(const SCHAR* items,
break; break;
case isc_info_record_errors: case isc_info_record_errors:
err_att = tdbb->tdbb_attachment;
if (err_att->att_val_errors) { if (err_att->att_val_errors) {
err_val = err_val =
(*err_att->att_val_errors)[VAL_REC_CHAIN_BROKEN] (*err_att->att_val_errors)[VAL_REC_CHAIN_BROKEN]
@ -627,7 +637,6 @@ int INF_database_info(const SCHAR* items,
break; break;
case isc_info_dpage_errors: case isc_info_dpage_errors:
err_att = tdbb->tdbb_attachment;
if (err_att->att_val_errors) { if (err_att->att_val_errors) {
err_val = err_val =
(*err_att->att_val_errors)[VAL_DATA_PAGE_CONFUSED] (*err_att->att_val_errors)[VAL_DATA_PAGE_CONFUSED]
@ -641,7 +650,6 @@ int INF_database_info(const SCHAR* items,
break; break;
case isc_info_ipage_errors: case isc_info_ipage_errors:
err_att = tdbb->tdbb_attachment;
if (err_att->att_val_errors) { if (err_att->att_val_errors) {
err_val = err_val =
(*err_att->att_val_errors)[VAL_INDEX_PAGE_CORRUPT] + (*err_att->att_val_errors)[VAL_INDEX_PAGE_CORRUPT] +
@ -657,7 +665,6 @@ int INF_database_info(const SCHAR* items,
break; break;
case isc_info_ppage_errors: case isc_info_ppage_errors:
err_att = tdbb->tdbb_attachment;
if (err_att->att_val_errors) { if (err_att->att_val_errors) {
err_val = (*err_att->att_val_errors)[VAL_P_PAGE_LOST] err_val = (*err_att->att_val_errors)[VAL_P_PAGE_LOST]
+ +
@ -670,7 +677,6 @@ int INF_database_info(const SCHAR* items,
break; break;
case isc_info_tpage_errors: case isc_info_tpage_errors:
err_att = tdbb->tdbb_attachment;
if (err_att->att_val_errors) { if (err_att->att_val_errors) {
err_val = (*err_att->att_val_errors)[VAL_TIP_LOST] err_val = (*err_att->att_val_errors)[VAL_TIP_LOST]
+ (*err_att->att_val_errors)[VAL_TIP_LOST_SEQUENCE] + (*err_att->att_val_errors)[VAL_TIP_LOST_SEQUENCE]