Skip to content

Commit 11cfb2a

Browse files
committed
Better backward compatibility. Some paranoid checks in gbak.
1 parent 3034fc6 commit 11cfb2a

File tree

2 files changed

+39
-22
lines changed

2 files changed

+39
-22
lines changed

src/burp/backup.epp

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ void put_blob( burp_fld* field, ISC_QUAD& blob_id)
12591259
return;
12601260
}
12611261

1262-
UCHAR blob_info[32];
1262+
UCHAR blob_info[BUFFER_TINY];
12631263
if (!blob.getInfo(sizeof(blob_items), blob_items, sizeof(blob_info), blob_info))
12641264
{
12651265
BURP_error_redirect(&status_vector, 20);
@@ -1388,32 +1388,33 @@ bool put_blr_blob( att_type attribute, ISC_QUAD& blob_id)
13881388
// msg 24 isc_open_blob failed
13891389
}
13901390

1391-
UCHAR blob_info[32];
1391+
UCHAR blob_info[BUFFER_TINY];
13921392
if (!blob.getInfo(sizeof(blr_items), blr_items, sizeof(blob_info), blob_info))
13931393
{
13941394
BURP_error_redirect(&status_vector, 20);
13951395
// msg 20 isc_blob_info failed
13961396
}
13971397

1398-
ULONG length = 0;
1398+
FB_UINT64 length = 0;
13991399
USHORT max_segment = 0;
14001400
const UCHAR* p = blob_info;
14011401
UCHAR item;
14021402

14031403
while ((item = *p++) != isc_info_end)
14041404
{
1405-
const USHORT l = isc_vax_integer((const char*) p, 2);
1405+
const auto l = gds__vax_integer(p, 2);
14061406
p += 2;
1407-
const ULONG n = isc_vax_integer((const char*) p, l);
1407+
const auto n = isc_portable_integer(p, l);
14081408
p += l;
1409+
14091410
switch (item)
14101411
{
14111412
case isc_info_blob_max_segment:
1412-
max_segment = n;
1413+
max_segment = (USHORT) n;
14131414
break;
14141415

14151416
case isc_info_blob_total_length:
1416-
length = n;
1417+
length = (FB_UINT64) n;
14171418
break;
14181419

14191420
default:
@@ -1426,7 +1427,7 @@ bool put_blr_blob( att_type attribute, ISC_QUAD& blob_id)
14261427
}
14271428
}
14281429

1429-
if (!length)
1430+
if (!length || length > MAX_ULONG)
14301431
{
14311432
if (!blob.close())
14321433
BURP_error_redirect(&status_vector, 23);
@@ -2136,37 +2137,38 @@ bool put_source_blob(att_type attribute, att_type old_attribute, ISC_QUAD& blob_
21362137
// msg 24 isc_open_blob failed
21372138
}
21382139

2139-
UCHAR blob_info[48];
2140+
UCHAR blob_info[BUFFER_TINY];
21402141
if (!blob.getInfo(sizeof(source_items), source_items, sizeof(blob_info), blob_info))
21412142
{
21422143
BURP_error_redirect(&status_vector, 20);
21432144
// msg 20 isc_blob_info failed
21442145
}
21452146

2146-
ULONG length = 0;
2147+
FB_UINT64 length = 0;
21472148
ULONG num_seg = 0;
21482149
USHORT max_segment = 0;
21492150
const UCHAR* p = blob_info;
21502151
UCHAR item;
21512152

21522153
while ((item = *p++) != isc_info_end)
21532154
{
2154-
const USHORT l = gds__vax_integer(p, 2);
2155+
const auto l = gds__vax_integer(p, 2);
21552156
p += 2;
2156-
const ULONG n = gds__vax_integer(p, l);
2157+
const auto n = isc_portable_integer(p, l);
21572158
p += l;
2159+
21582160
switch (item)
21592161
{
21602162
case isc_info_blob_max_segment:
2161-
max_segment = n;
2163+
max_segment = (USHORT) n;
21622164
break;
21632165

21642166
case isc_info_blob_total_length:
2165-
length = n;
2167+
length = (FB_UINT64) n;
21662168
break;
21672169

21682170
case isc_info_blob_num_segments:
2169-
num_seg = n;
2171+
num_seg = (ULONG) n;
21702172
break;
21712173

21722174
default:
@@ -2181,7 +2183,7 @@ bool put_source_blob(att_type attribute, att_type old_attribute, ISC_QUAD& blob_
21812183
}
21822184
}
21832185

2184-
if (!length)
2186+
if (!length || length > MAX_ULONG)
21852187
{
21862188
if (!blob.close())
21872189
{
@@ -3881,8 +3883,11 @@ void write_relations()
38813883
// RDB$VIEW_BLR must be the first blob field in the backup file.
38823884
// RESTORE.EPP makes this assumption in get_relation().
38833885

3884-
if (put_blr_blob (att_relation_view_blr, X.RDB$VIEW_BLR))
3886+
if (!X.RDB$VIEW_BLR.NULL && !BlobWrapper::blobIsNull(X.RDB$VIEW_BLR))
38853887
flags |= REL_view;
3888+
3889+
put_blr_blob (att_relation_view_blr, X.RDB$VIEW_BLR);
3890+
38863891
if (X.RDB$SYSTEM_FLAG)
38873892
put_int32 (att_relation_system_flag, X.RDB$SYSTEM_FLAG);
38883893
if (!X.RDB$FLAGS.NULL)
@@ -3941,8 +3946,10 @@ void write_relations()
39413946
// RDB$VIEW_BLR must be the first blob field in the backup file.
39423947
// RESTORE.EPP makes this assumption in get_relation().
39433948

3944-
if (put_blr_blob (att_relation_view_blr, X.RDB$VIEW_BLR))
3949+
if (!X.RDB$VIEW_BLR.NULL && !BlobWrapper::blobIsNull(X.RDB$VIEW_BLR))
39453950
flags |= REL_view;
3951+
3952+
put_blr_blob (att_relation_view_blr, X.RDB$VIEW_BLR);
39463953
if (X.RDB$SYSTEM_FLAG)
39473954
put_int32 (att_relation_system_flag, X.RDB$SYSTEM_FLAG);
39483955
if (!X.RDB$FLAGS.NULL)

src/remote/remote.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -873,28 +873,38 @@ bool RBlobInfo::getLocalInfo(unsigned int itemsLength, const unsigned char* item
873873
if (*item == isc_info_end)
874874
break;
875875

876+
FB_UINT64 value;
877+
876878
switch (*item)
877879
{
878880
case isc_info_blob_num_segments:
879-
p = fb_utils::putInfoItemInt(*item, num_segments, p, end);
881+
value = num_segments;
880882
break;
881883

882884
case isc_info_blob_max_segment:
883-
p = fb_utils::putInfoItemInt(*item, max_segment, p, end);
885+
value = max_segment;
884886
break;
885887

886888
case isc_info_blob_total_length:
887-
p = fb_utils::putInfoItemInt(*item, total_length, p, end);
889+
value = total_length;
888890
break;
889891

890892
case isc_info_blob_type:
891-
p = fb_utils::putInfoItemInt(*item, blob_type, p, end);
893+
value = blob_type;
892894
break;
893895

894896
default:
895897
// unknown info item, let remote server handle it
896898
return false;
897899
}
900+
901+
if (value <= MAX_SLONG)
902+
p = fb_utils::putInfoItemInt(*item, (SLONG) value, p, end);
903+
else
904+
p = fb_utils::putInfoItemInt(*item, value, p, end);
905+
906+
if (!p)
907+
return false;
898908
}
899909

900910
if (p < end)

0 commit comments

Comments
 (0)