mergecap: prevent appending to an input file
Prevent the infinite loop described in #19402 by refusing to operate if asked to append to an output file that is also one of the inputs. Uses `files_identical()` from wsutil.
This commit is contained in:
parent
e2a3acefe9
commit
3b63098fb1
|
@ -416,6 +416,15 @@ main(int argc, char *argv[])
|
||||||
cfile_close_failure_message(out_filename, err, err_info);
|
cfile_close_failure_message(out_filename, err, err_info);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case MERGE_ERR_INVALID_OPTION:
|
||||||
|
if (err_info) {
|
||||||
|
cmdarg_err("%s", err_info);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cmdarg_err("Unspecified error with merge option");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
cmdarg_err("Unknown merge_files error %d", status);
|
cmdarg_err("Unknown merge_files error %d", status);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1417,6 +1417,22 @@ merge_files(const gchar* out_filename, const int file_type,
|
||||||
guint32 *err_framenum)
|
guint32 *err_framenum)
|
||||||
{
|
{
|
||||||
ws_assert(out_filename != NULL);
|
ws_assert(out_filename != NULL);
|
||||||
|
ws_assert(in_file_count > 0);
|
||||||
|
ws_assert(in_filenames != NULL);
|
||||||
|
ws_assert(err_info != NULL);
|
||||||
|
|
||||||
|
/* #19402: ensure we aren't appending to one of our inputs */
|
||||||
|
if (do_append) {
|
||||||
|
unsigned int i;
|
||||||
|
for (i = 0; i < in_file_count; i++) {
|
||||||
|
if (files_identical(out_filename, in_filenames[i])) {
|
||||||
|
*err_info = ws_strdup_printf("Output file %s is same as input file %s; "
|
||||||
|
"appending would create infinite loop",
|
||||||
|
out_filename, in_filenames[i]);
|
||||||
|
return MERGE_ERR_INVALID_OPTION;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return merge_files_common(out_filename, NULL, NULL,
|
return merge_files_common(out_filename, NULL, NULL,
|
||||||
file_type, in_filenames, in_file_count,
|
file_type, in_filenames, in_file_count,
|
||||||
|
|
Loading…
Reference in New Issue