Fixed the GTK file chooser handling to avoid dereferencing/processing invalid filenames by adding an early guard in gtkutil_check_file() for NULL/empty selections, which prevents the load flow from continuing with bad input.

Fixed the single-file open path in gtkutil_file_req_done() to fetch the filename once and only call gtkutil_check_file() when a non-NULL filename is returned, preventing the crash path when GTK returns no file on accept/load.
This commit is contained in:
2026-02-15 15:02:26 -07:00
parent 371b1caaa6
commit 95538794e3

View File

@@ -362,6 +362,12 @@ gtkutil_check_file (char *filename, struct file_req *freq)
{
int axs = FALSE;
if (filename == NULL || filename[0] == '\0')
{
fe_message (_("No file selected."), FE_MSG_ERROR);
return;
}
GFile *file = g_file_new_for_path (filename);
if (freq->flags & FRF_WRITE)
@@ -453,8 +459,11 @@ gtkutil_file_req_done (GtkWidget * wid, struct file_req *freq)
else
{
gchar *filename = gtk_file_chooser_get_filename (fs);
gtkutil_check_file (gtk_file_chooser_get_filename (fs), freq);
g_free (filename);
if (filename != NULL)
{
gtkutil_check_file (filename, freq);
g_free (filename);
}
}
}