dumpcap: Fix segfault when failing to create temporary file

g_file_open_tmp() does not set name_used unless the temp file
is successfully created (cf. to our old hand written library
pre commit 2925fb0850). Initialize it so that g_free doesn't
free a random memory location in that case, and don't use it
otherwise after failure. Fix #17828.
This commit is contained in:
John Thacker 2022-01-19 08:05:10 -05:00 committed by A Wireshark GitLab Utility
parent f7b6ebcc04
commit 3e2c79d924
2 changed files with 4 additions and 4 deletions

View File

@ -3538,7 +3538,7 @@ static gboolean
capture_loop_open_output(capture_options *capture_opts, int *save_file_fd,
char *errmsg, int errmsg_len)
{
gchar *capfile_name;
gchar *capfile_name = NULL;
gchar *prefix, *suffix;
gboolean is_tempfile;
GError *err_tempfile = NULL;
@ -3687,8 +3687,8 @@ capture_loop_open_output(capture_options *capture_opts, int *save_file_fd,
if (*save_file_fd == -1) {
if (is_tempfile) {
snprintf(errmsg, errmsg_len,
"The temporary file to which the capture would be saved (\"%s\") "
"could not be opened: %s.", capfile_name, err_tempfile->message);
"The temporary file to which the capture would be saved "
"could not be opened: %s.", err_tempfile->message);
g_error_free(err_tempfile);
} else {
if (capture_opts->multi_files_on) {

View File

@ -35,7 +35,7 @@ do_export_pdu(const char *filter, const gchar *tap_name)
char *error;
int import_file_fd;
int file_type_subtype;
char *capfile_name, *comment;
char *capfile_name = NULL, *comment;
gboolean status;
int err;
gchar *err_info;