merge: Don't write to stdout if tempdir is not set

If merge_files_common() is called with a non NULL value for out_filenamep,
that always indicates tempfile mode, even if the tempdir is not set.
A NULL value for the tempdir is handled by wtap_dump_open_tempfile,
which writes to the OS default temp directory.

Only write to stdout if both out_filename and out_filenamep are NULL.

Fixes a crash introduced by commit 1e0d117eb7
when selecting Merge from the GUI and the new temp_dir option is not set.
This commit is contained in:
John Thacker 2022-05-13 09:19:16 -04:00 committed by A Wireshark GitLab Utility
parent bebf7afa37
commit 1f1ee198f2
1 changed files with 6 additions and 5 deletions

View File

@ -985,7 +985,8 @@ merge_process_packets(wtap_dumper *pdh, const int file_type,
}
static merge_result
merge_files_common(const gchar* out_filename, /* normal output mode */
merge_files_common(const gchar* out_filename, /* filename in normal output mode,
optional tempdir in tempfile mode (NULL for OS default) */
gchar **out_filenamep, const char *pfx, /* tempfile mode */
const int file_type, const char *const *in_filenames,
const guint in_file_count, const gboolean do_append,
@ -1065,13 +1066,13 @@ merge_files_common(const gchar* out_filename, /* normal output mode */
dsb_combined = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
params.dsbs_growing = dsb_combined;
}
if (out_filename && !out_filenamep) {
pdh = wtap_dump_open(out_filename, file_type, WTAP_UNCOMPRESSED,
&params, err, err_info);
} else if (out_filename && out_filenamep) {
if (out_filenamep) {
pdh = wtap_dump_open_tempfile(out_filename, out_filenamep, pfx, file_type,
WTAP_UNCOMPRESSED, &params, err,
err_info);
} else if (out_filename) {
pdh = wtap_dump_open(out_filename, file_type, WTAP_UNCOMPRESSED,
&params, err, err_info);
} else {
pdh = wtap_dump_open_stdout(file_type, WTAP_UNCOMPRESSED, &params, err,
err_info);