Skip to content

Commit 85e3360

Browse files
committed
Resolve database aliases before comparing input/output paths in gbak
When gbak -b is called with a database alias as source and the resolved path as destination (e.g., gbak -b db_alias /path/to/db.gdb), the duplicate file check in the validation loop only compared raw strings, missing the overlap. This could silently overwrite the live database with backup data. Enhance the existing all-pairs file comparison loop to expand both paths via expandDatabaseName() (already used for one side) and emit the correct error: msg 11 (input and output have the same name) when source matches a destination, msg 9 (multiple sources or destinations) for duplicate destinations.
1 parent 806dab4 commit 85e3360

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/burp/burp.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,21 +1162,23 @@ int gbak(Firebird::UtilSvc* uSvc)
11621162
Firebird::PathName expanded;
11631163
expandDatabaseName(file->fil_name, expanded, NULL);
11641164

1165+
const bool isSource = (file->fil_name.c_str() == file1);
1166+
11651167
for (file_list = file->fil_next; file_list;
11661168
file_list = file_list->fil_next)
11671169
{
1168-
if (file->fil_name == file_list->fil_name || expanded == file_list->fil_name)
1169-
{
1170-
BURP_error(9, true);
1171-
// msg 9 mutiple sources or destinations specified
1172-
}
1173-
11741170
Firebird::PathName expanded2;
11751171
expandDatabaseName(file_list->fil_name, expanded2, NULL);
1176-
if (file->fil_name == expanded2 || expanded == expanded2)
1172+
1173+
if (file->fil_name == file_list->fil_name || expanded == file_list->fil_name ||
1174+
file->fil_name == expanded2 || expanded == expanded2)
11771175
{
1178-
BURP_error(9, true);
1179-
// msg 9 mutiple sources or destinations specified
1176+
if (isSource)
1177+
BURP_error(11, true);
1178+
// msg 11 input and output have the same name. Disallowed.
1179+
else
1180+
BURP_error(9, true);
1181+
// msg 9 mutiple sources or destinations specified
11801182
}
11811183
}
11821184

0 commit comments

Comments
 (0)