file-operation: Return early when basename is NULL

Calling g_utf8_validate() on a NULL string crashes Nautilus.  This
can occur if performing an operation on an invalid file. If
basename is NULL, there's nothing we would do anyways, so just
return early and prevent the crash.

There's a similar issue with get_unique_target_file(), but
if a bad uri was passed to this function it should fail much
earlier, so lets just add an assertion.

Fixes: https://gitlab.gnome.org/GNOME/nautilus/-/issues/2376
This commit is contained in:
Corey Berla 2022-11-25 15:21:58 -08:00 committed by António Fernandes
parent b34ea39892
commit e2969a9c29

View file

@ -1022,6 +1022,11 @@ get_basename (GFile *file)
if (name == NULL)
{
basename = g_file_get_basename (file);
if (basename == NULL)
{
return g_strdup (_("unknown"));
}
if (g_utf8_validate (basename, -1, NULL))
{
name = basename;
@ -4384,6 +4389,7 @@ get_unique_target_file (GFile *src,
if (dest == NULL)
{
basename = g_file_get_basename (src);
g_assert (basename == NULL);
if (g_utf8_validate (basename, -1, NULL))
{